Oracle存储过程-返回一个查询的结果集

创建一个返回select结果集的存储过程: 

--创建procedure

create or replace procedure pro_emp(resule out sys_refcursor) is
begin
  open resule for select * from emp;
end;

 调用:

--调用
declare
  cur1   SYS_REFCURSOR;
  result_row      emp%rowtype;
begin

 pro_emp(cur1);

  loop
    fetch cur1
      into result_row;
    exit when cur1%notfound;

    dbms_output.put_line('员工姓名:' || result_row.ename);
  end loop;

  close cur1;

end;

打印输出结果:

员工姓名:SMITH
员工姓名:ALLEN
员工姓名:WARD
员工姓名:JONES
员工姓名:MARTIN
员工姓名:BLAKE
员工姓名:CLARK
员工姓名:SCOTT
员工姓名:KING
员工姓名:TURNER
员工姓名:ADAMS
员工姓名:JAMES
员工姓名:FORD
员工姓名:MILLER
 

    原文作者:梁萌
    原文地址: https://blog.csdn.net/liangmengbk/article/details/101196104
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞