I want to write a function which can be used to format a faculty member's salary (FACULTY being a table, where each row is a member) to $9,999,999.99 without hard coding the exact salary datatype (i.e the function should work even if in the future minor changes are made to the salary data size/type). I want to be able to use this function in a SQL statement for displaying a faculty member's salary.
Here is what my function code looks like right now.
CREATE OR REPLACE FUNCTION FUNC_FORMAT_SAL(fid IN FACULTY.F_ID%TYPE)
RETURN NUMBER IS
sal NUMBER;
BEGIN
SELECT FACULTY.F_SALARY INTO sal FROM FACULTY
WHERE FACULTY.F_ID = fid;
RETURN sal;
END;
I understand that in PLSQL a function cannot return a void right? That is why I have taken the member's F_ID as an IN input into the function. Inside this function, I want to format the SALARY for that member so that it could be displayed when I call an SQL statement, and then return the formatted salary.
Am I making any sense? This is a tutorial question in class and I just can seem to understand even though easy it appears to be.
void). But it can return the valuenull. If you want an "executable object", which doesn't necessarily return something, but typically changes something in the database, you might be looking for aPROCEDURE.