Hi there..

I'm having a problem in this code .. it is a function.

actually it works perfectly if i didn't use the conditional statement
because of the avg..

Can anybody can figure out the problem ?

Code:
CREATE OR REPLACE FUNCTION empid
(id in  employees.employee_id%type)

return varchar2 is 
sal varchar2(150);
empSalary  employees.salary%type:=0;
avg employees.salary%type:=0;
eid employees.employee_id%type;

begin

select  avg(salary) ,salary, employee_id into avg, empsalary,eid from employees
group by department_id, salary , employee_id
having employee_id=id ;

if empsalary>avg then
sal:= 'Here is the msg' ;
else 
sal:= 'Here is the msg2' ;

end if;

return sal;

end empid;
/
Bishoujo