The above function takes in two parameters, namely organization_id and a parameter for choice. Based on the choice, the function will return either the organization name or the organization short code from two different select statements.

In case no data is found, it will return null, and in case of error, it will return the error message.

Note the following:
a. I am hard-coding the Master Organization Id in this case since I am using writing this script for one of the Operating Units in a multi-Org structure. Since I can have only one Master Organization per Operating Unit, I have hard-coded this value to restrict my Organizations and to keep the code simple.

The above function takes in two parameters, namely employee_id and a parameter for choice. Based on the choice, the function will return either the employee number, his full name or his email address.

In case no data is found, it will return null, and in case of error, it will return the error message.

Note the following:
a. The additional parameter ‘p_choice’ allows me the flexibility of using the same function to return different columns from the same select statement as required. You could have added more choices to enable you to return other fields. This gives me two advantage: I do not need to build a separate function for each and it simplifies my joins in eventual select statements as I have one table less to join.
b. Instead of making p_choice a number, I have made it a character. You can argue that I could have put remarks besides each number, but as preferred varchar2 as this makes its usage more intuitive.
c. I used the standard function ‘upper’ to further allows for any combination of cases when passing parameter p_choice.
d. Before checking for actual cases, I check whether there is an error in entering parameters
e. In case of no data found, I am returning null instead of the error code. I am returning the error messages in case of other errors. You could have opted otherwise.

I am using this structure and logic to build a series of simple functions that will allow me simplifies my eventual queries in the future.