I am attempting to create a procedure using cursors to list the average salary of all employees on a per department basis. I am using three tables, defined as
emp(eid, ename, age, salary)
works(eid, did, pct_time)
dept(did, dname, budget, managerid)
The procedure is compiling with errors. What am I doing wrong? Please see the procedure definition below.
create or replace procedure get_avgSalary(ddept_id in dept.did%type) is cursor c1 is select avg(e.salary) from emp e, works w, dept d where e.eid=w.eid and d.did = w.did group by w.did; avg_sal c1%rowtype; begin for avg_sal in c1 loop dbms_output.put_line('Average salary of the employees in department ' || ddept_id ||' is '|| avg_sal.salary); end loop; end; /
I have to use a cursor. It is part of my assignment.