oracle ref cursor return,ORACLE ref cursor的简单使用

本篇文章的目的是通过建一个存储过程来返回一个结果集合,并通过前台调用把结果集展示出来

--建立存储过程,参数类型为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_tempv_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;

总结

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值