declare
type sp_emp_cursor is ref cursor;
test_cursor sp_emp_cursor;
v_ename pme.ename%type;
v_sal pme.sal%type;
begin
open test_cursor for select ename,sal from pme where deptno=&deptno;
loop
fetch test_cursor into v_ename,v_sal;
exit when test_cursor%notfound;(1)
dbms_output.put_line('名字:'||v_ename||',工资'||v_sal);
end loop;
end;
请问,如果没有(1)这句话,就是死循环,那么死循环为什么会老是打印最后一组数据呢?而不是打印空值什么的?
type sp_emp_cursor is ref cursor;
test_cursor sp_emp_cursor;
v_ename pme.ename%type;
v_sal pme.sal%type;
begin
open test_cursor for select ename,sal from pme where deptno=&deptno;
loop
fetch test_cursor into v_ename,v_sal;
exit when test_cursor%notfound;(1)
dbms_output.put_line('名字:'||v_ename||',工资'||v_sal);
end loop;
close test_cursor;
end;
SQL> declare
2 type sp_emp_cursor is ref cursor;
3 test_cursor sp_emp_cursor;
4 v_ename emp.ename%type;
5 v_sal emp.sal%type;
6 begin
7 open test_cursor for select ename,sal from emp where deptno=&deptno;
8 loop
9 fetch test_cursor into v_ename,v_sal;
10 exit when test_cursor%notfound;
11 dbms_output.put_line('名字:'||v_ename||',工资'||v_sal);
12 end loop;
13 close test_cursor;
14 end;
15 /
输入 deptno 的值: 10
原值 7: open test_cursor for select ename,sal from emp where deptno=&deptno;
新值 7: open test_cursor for select ename,sal from emp where deptno=10;
名字:CLARK,工资2450
名字:KING,工资5000
名字:MILLER,工资1300PL/SQL 过程已成功完成。