【发布时间】:2021-06-22 18:56:15
【问题描述】:
我需要打印部门游标从部门表中获取的那些部门中的雇员姓名(来自雇员表)。
我尝试执行以下代码。
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;
但我在第 18 行收到一条错误消息:
错误报告 -
ORA-01001: 无效游标
ORA-06512: 在第 18 行
01001. 00000 - “无效光标”
*原因:
*行动:
帮我纠正这个问题:P
【问题讨论】: