首页 > 解决方案 > 从参考游标返回值到客户端

问题描述

将 ref 游标返回给客户端意味着什么以及如何将 ref 游标值传递给 oracle 中的其他程序。请帮帮我。

提前致谢

标签: plsql

解决方案


好的,下面是在 sqlplus 中返回 ref 游标的过程、函数和匿名块的示例:

ops$tkyte@ORA817DEV.US.ORACLE.COM> create or replace package types
2 as
3 type rc is ref cursor;
4 end;
5 /

包创建。

ops$tkyte@ORA817DEV.US.ORACLE.COM>
ops$tkyte@ORA817DEV.US.ORACLE.COM>
ops$tkyte@ORA817DEV.US.ORACLE.COM> create or replace procedure get_cursor_proc( p_cursor in out types.rc )
2 is
3 begin
4 open p_cursor for select * from dual;
5 end;
6 /

程序已创建。

ops$tkyte@ORA817DEV.US.ORACLE.COM>
ops$tkyte@ORA817DEV.US.ORACLE.COM> create or replace function get_cursor_func return types.rc
2 as
3 l_cursor types.rc;
4 begin
5 open l_cursor for select * from dual;
6 return l_cursor;
7 end;
8 /

创建的函数。

ops$tkyte@ORA817DEV.US.ORACLE.COM>
ops$tkyte@ORA817DEV.US.ORACLE.COM>
ops$tkyte@ORA817DEV.US.ORACLE.COM> variable x refcursor
ops$tkyte@ORA817DEV.US.ORACLE.COM> set autoprint on
ops$tkyte@ORA817DEV.US.ORACLE.COM>
ops$tkyte@ORA817DEV.US.ORACLE.COM> REM procedure
ops$tkyte@ORA817DEV.US.ORACLE.COM> exec get_cursor_proc(:x)

PL/SQL 过程成功完成。

D

X

ops$tkyte@ORA817DEV.US.ORACLE.COM>
ops$tkyte@ORA817DEV.US.ORACLE.COM> REM function
ops$tkyte@ORA817DEV.US.ORACLE.COM> exec :x := get_cursor_func

PL/SQL 过程成功完成。

D

X

ops$tkyte@ORA817DEV.US.ORACLE.COM>
ops$tkyte@ORA817DEV.US.ORACLE.COM> REM anonymous block
ops$tkyte@ORA817DEV.US.ORACLE.COM> begin
2 open :x for select * from dual;
3 end;
4 /

PL/SQL 过程成功完成。

D

X


推荐阅读