加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ORACLE ref cursor的简单使用

发布时间:2020-12-12 15:43:54 所属栏目:百科 来源:网络整理
导读:本篇文章的目的是通过建一个存储过程来返回一个结果集合,并通过前台调用把结果集展示出来 --建立存储过程,参数类型为OUT SYS_REFCURSOR create or replace procedure test_ref_cursor(v_cursor out sys_refcursor) as begin open v_cursor for select * fr

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读