将游标从内部过程返回到oracle pl / sql中的外部过程 [英] Returning a cursor from an inner procedure to outer procedure in oracle pl/sql
问题描述
我使用oracle PL / SQL过程。
我在另一个程序中调用一个过程。我想将一个游标从嵌套过程返回到外部过程。
这是可能吗?
它对程序有什么不利影响?
I am using oracle PL/SQL procedure. I am calling one procedure inside another. I want to return a cursor from the nested procedure to the outer procedure. Is this possible? How adversely does it affect the procedure?
下面是调用结构:
Proc1( data1 IN integer, cursor1 OUT SYS_REFCURSOR ) {
Proc2(data2 IN , cursor1 out) {
open cursor1 FOR
select * from table;
}
}
推荐答案
这是一个具有REF CURSOR OUT参数的调用过程的示例。
Here is one example of calling procedures that have REF CURSOR OUT parameters.
SQL> create or replace procedure p1(
2 p_empno in emp.empno%type,
3 p_rc out sys_refcursor
4 )
5 as
6 begin
7 open p_rc
8 for
9 select *
10 from emp
11 where empno = p_empno;
12 end;
13 /
Procedure created.
SQL> create or replace procedure p2(
2 p_empno in emp.empno%type,
3 p_rc out sys_refcursor
4 )
5 as
6 begin
7 p1( p_empno, p_rc );
8 end;
9 /
Procedure created.
在这种情况下,我创建一个SQL * Plus替换变量rc,调用p2。如果你使用SQL * Plus以外的语言调用它,语法会有所不同,但一般的原则是一样的。
In this case, I'm creating a SQL*Plus substitution variable rc in order to demonstrate how to call p2. If you are calling it in something other than SQL*Plus, the syntax will be a bit different but the general principle will be the same.
SQL> var rc refcursor;
SQL> exec p2( 7900, :rc );
PL/SQL procedure successfully completed.
SQL> print rc
EMPNO ENAME JOB MGR HIREDATE SAL COMM
---------- ---------- --------- ---------- --------- ---------- ----------
DEPTNO FAKE_COL FOO
---------- ---------- ----------
7900 SM2 CLERK 7698 03-DEC-81 950
30 1
这篇关于将游标从内部过程返回到oracle pl / sql中的外部过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!