sys_refcursor的使用(oracle自定义游标)
2009-12-14 18:00
591 查看
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:
Here's a table that we will use to select from:
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.
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
相关文章推荐
- Oracle 参照游标(SYS_REFCURSOR)使用
- oracle游标应用难点 sys_refcursor 和 cursor
- oracle游标应用 sys_refcursor 和 cursor比较
- Oracle动态sql返回游标(sys_refcursor)
- oracle游标应用难点 sys_refcursor 和 cursor(转)
- oracle游标应用难点 sys_refcursor 和 cursor(转)
- Oracle sys_refcursor 游标变量不能用作参数传递
- oracle存储过程中使用Ref Cursor强类型游标返回结果集
- oracle 存储过程返回 结果集 table形式 (使用sys_refcursor 及程序包package 两种方式)
- oracle 中 cursor 与refcursor及sys_refcursor的区别 (转载)
- 参考游标(refcursor)的使用
- Oracle Procedure中使用游标cursor更新多表
- C++使用ADO访问Oracle返回结果集(REF CURSOR)存储过程
- oracle 中 cursor 与refcursor及sys_refcursor的区别 (转载)
- oracle 存储过程及REF CURSOR的使用
- ORACLE中用for in 使用cursor 游标
- 使用REF CURSOR处理Oracle的结果集
- ORACLE游标(cursor)的使用
- Oracle ref cursor使用
- oracle 中 cursor 与refcursor及sys_refcursor的区别 (转载)