我在包中有一个函数,它也有一个输出变量
create package sum_pkg
TYPE rc is REF CURSOR;
function sum_detail
(
p_name in varchar2,
p_out out varchar2
)
return rc
as
begin
...
end;
/
我正在测试如下但出现错误:
var x REFCURSOR;
exec :x := sum_pkg.sum_detail ( p_name = 'abc', p_out => :x ) ;
print :x
但我得到:标识符 X 必须声明。
您确定想要返回两个值吗?代码表明该函数返回引用游标以及 OUT 参数。如果您是,那么这里有一个示例,展示了如何做到这一点:
SQL> create or replace function sum_detail
2 (p_name in varchar2,
3 p_out out varchar2)
4 return sys_refcursor is
5 rc sys_refcursor;
6 begin
7 select job into p_out
8 from emp
9 where ename = p_name;
10
11 open rc for select ename from emp
12 where job = p_out;
13
14 return rc;
15 end;
16 /
Function created.
测试:
SQL> set serveroutput on;
SQL> declare
2 l_job varchar2(20);
3 l_rc sys_refcursor;
4 l_ename varchar2(20);
5 begin
6 l_rc := sum_detail('SCOTT', l_job);
7
8 loop
9 fetch l_rc into l_ename;
10 exit when l_rc%notfound;
11 dbms_output.put_line(l_ename);
12 end loop;
13 end;
14 /
SCOTT
FORD
PL/SQL procedure successfully completed.
SQL>