sys_refcursor的使用(oracle自定义游标)

sys_refcursor can be used to pass cursors from and to a stored precedure.
The following procedure proc_ref_cursor accepts a sys_refcursor and loops on that cursor and prints out ( dbms_output) what it fetches:
create or replace procedure 
  proc_ref_cursor (rc in sys_refcursor) as

  v_a number;
  v_b varchar2(10);
  
begin
  loop
    fetch rc into v_a, v_b;
    exit when rc%notfound;
    dbms_output.put_line(v_a || ' ' || v_b);
  end loop;
end;
/

Here's a table that we will use to select from:
create table table_ref_cursor (
  a number,
  b varchar2(10)
);

insert into table_ref_cursor values(1, 'one');
insert into table_ref_cursor values(2, 'two');
insert into table_ref_cursor values(3, 'three');
insert into table_ref_cursor values(4, 'four');

commit;
Here's another stored procedure ( call_proc_ref_cursor) that opens a cursor ( select * from table_ref_cursor) and passes that cursor to proc_ref_cursor.
create or replace procedure 
  call_proc_ref_cursor as

  v_rc sys_refcursor;

begin

  open v_rc for 
    select * from table_ref_cursor;

  proc_ref_cursor(v_rc);

  close v_rc;
end;
/
转自:http://www.adp-gmbh.ch/ora/sql/sys_refcursor.html
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值