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_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;

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值