Hello everybody:

I have been working on this function problem for over two days (homework assignment). I cannot figure out how to do it and am not finding any help in doing this. Here is the problem:

Create PL/SQL function (EMP_SAL_DIFF) that accepts an employee number (P_EMPLOYEE_ID) and returns the difference between the average salary in the department the employee works for and the employee’s salary.

In addition, create a driver program that runs the function against every employee in the EMPLOYEES table. Show all work including the output from running the procedure.


Here is the work that I have done so far, but its only the part about obtaining the salary for a certain employee.

Create or replace function get_Sal ( P_EID IN NUMBER) RETURN NUMBER
IS
V_SAL EMPLOYEES.SALARY%TYPE;
BEGIN
SELECT SALARY
INTO V_SAL
FROM EMPLOYEES
WHERE EMPLOYEE_ID = P_EID;
RETURN V_SAL;
END;
/
variable g_sal NUMBER
EXECUTE :g_sal := get_Sal (199)
Print g_sal

Help would be greatly appreciated!! I think I've pulled out all my hair while trying to do this.