I have a requirement to print the employee names (from the employee table) in those departments which are fetched by the department cursor from the departments table.
I tried executing the following code.
declare
type tn is ref cursor;
deptemp_cur tn;
v_dno DEPARTMENTS.DEPARTMENT_ID%type;
v_dname departments.department_name%type;
v_ename employees.first_name%type;
begin
open deptemp_cur for select DEPARTMENT_ID,department_name from DEPARTMENTS where DEPARTMENT_ID<40;
loop
fetch deptemp_cur into v_dno, v_dname;
open deptemp_cur for select first_name from employees where DEPARTMENT_ID=v_dno;
loop
fetch deptemp_cur into v_ename;
dbms_output.put_line(v_dno||' '||v_ename);
exit when deptemp_cur%notfound;
end loop;
close deptemp_cur;
exit when deptemp_cur%notfound; -- line 18
end loop;
close deptemp_cur;
end;
But I am getting an error at line 18 stating:
Error report -
ORA-01001: invalid cursor
ORA-06512: at line 18
01001. 00000 - "invalid cursor"
*Cause:
*Action:
Help me in rectifying this :P