Stored procedure using cursors 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.
You are trying to output avg_sal.salary which is not defined. Use alias in the cursor body :

.... cursor c1 is  select avg(e.salary)  AS salary ... 

Side notes. 
 It seems that parameter passed (ddept_id ) is not used anywhere inside the procedure except printing. Also, it's been long time since JOIN syntax was introduced and it's much more readable compared to SQL89 style (and recommended by Oracle as well). Finally, using cursor in this case seems quite questionable to me...