Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Function to find Average salary

602627Oct 20 2007 — edited Oct 21 2007
Hello everyone,

First of all I would like to say that I am a newbie to PL/SQL so please be patient with me. I am trying to create a function that will calculate the average salary for employees and compare the average salary to each employee's salary. If the employee's salary is lower than the average salary, my function will return true, elese it will return false.

I think I have a great start but need some guidance on what to do next. Here's my function so far:

CREATE OR REPLACE FUNCTION check_employee_salary
(p_empno IN NUMBER)
RETURN NUMBER
IS
lv_sal emp.sal%TYPE;
BEGIN
SELECT avg(sal)
INTO lv_sal
FROM emp
WHERE empno = p_empno;
RETURN (lv_sal);
END;
/

My function compiles but I can't figure out how to compare the avg(sal) to sal so that I can return true and false. Any guidance will be appreciated as I really want to understand PL/SQL and am trying very hard.

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 18 2007
Added on Oct 20 2007
5 comments
3,077 views