How to Return Result-Set via PLSQL Table or REF Cursor

How to Return Result-Set via PLSQL Table or REF Cursor
如何通过PLSQL 表 或者 REF Cursor 返回结果集

create or replace package test_pack is
type mycur is ref cursor;
type myrectype is record (loc varchar2(100));
type mytabtype is table of myrectype index by binary_integer;
end;
/

/* Procedure to Return resultset using REF Cursor */
create or replace procedure return_many_rows_ref(rset in out test_pack.mycur)
is
begin
open rset for select * from dept;
end;
/

/* Procedure to Return resultset using PL/SQL table of Records */
create or replace procedure return_many_rows_tabrec(rset in out test_pack.mytabtype)
is
cursor dept_cur is select loc from dept;
ctr number := 0;
begin
for x in dept_cur loop
rset(ctr).loc := x.loc;
ctr := ctr + 1;
end loop;
end;
/

/* PL/SQL block to test procedure that returns many rows using REF cursor */

set serveroutput on;

declare
result1 test_pack.mycur;
dep_rec dept%rowtype;
begin
return_many_rows_ref(result1);
loop
fetch result1 into dept_rec;
exit when result1%notfound;
dbms_output.put_line(dep_rec.deptno);
end loop;
close result1;
end;
/

/* PL/SQL block to test procedure that returns many rows using PL/SQL table of records*/

declare
result2 test_pack.mytabtype;
begin
return_many_rows_tabrec(result2);
for x in result2.first..result2.last loop
dbms_output.put_line(result2(x).loc);
end loop;
end;
/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值