oracle 存储过程返回游标变量

直接上代码

create or replace procedure pro_return_cursor(cur_test out sys_refcursor)
as 
begin 
  open cur_test for select * from emp;
end ;

================================================================

declare 
cur_test sys_refcursor;
v_emp emp%rowtype;
begin
  pro_return_cursor(cur_test);
loop 
  fetch cur_test into v_emp;
  exit when cur_test%notfound;  
 dbms_output.put_line(v_emp.empno||'  '||v_emp.ename);
 end loop;
 close cur_test;
end;

注意的地方就是:后面只能老老实实的使用loop 循环,不能使用for 循环
因为for 循环自带的打开游标,但是在存储过程中该游标已经被打开,不能使用for循环;

猜你喜欢

转载自blog.csdn.net/qq_39354340/article/details/81238229