本篇文章的目的是通过建一个存储过程来返回一个结果集合,并通过前台调用把结果集展示出来
--建立存储过程,参数类型为OUT SYS_REFCURSOR
create or replace procedure test_ref_cursor(v_cursor out sys_refcursor)
as
begin
open v_cursor for select * from emp;
end;
--方法一,通过sql PLUS 前台调用存储过程,代码块如下
sql> declare
2 type v_cursor is ref cursor RETURN emp%RowType;
3 v_cur v_cursor;
4 v_temp v_cur%rowtype;
5 begin
6 test_ref_cursor(v_cur);
7 loop
8 exit when v_cur%notfound;
9 fetch v_cur into v_temp;
10 dbms_output.put_line(v_temp.ename);
11 end loop;
12 close v_cur;
13 end;
14 /
declare
type v_cursor is ref cursor;
v_cur v_cursor;
v_temp emp%rowtype; begin open v_cur for select * from emp; loop exit when v_cur%notfound; fetch v_cur into v_temp; dbms_output.put_line('v_temp='||v_temp.ename); end loop; close v_cur; end;