我想得到一个在一个过程(b)中分配的列表,并将其作为OUT参数返回到过程(a)中的'table of varchar2'变量。如何定义OUT参数类型?
例)
procedure_a()
type t_list IS TABLE OF VARCHAR2(10)
l_list t_list;
procedure_b(l_list);
end procedure_a;
procedure_b(out_list OUT ????)
OUT类型是什么?
提前致谢。
答案 0 :(得分:5)
需要在A和B都可以引用的某个地方声明类型。一种选择是在包中声明类型,即
SQL> create package some_pkg
2 as
3 type t_list is table of varchar2(10);
4
5 procedure procedureA;
6 procedure procedureB( p_list OUT t_list );
7 end;
8
9 /
Package created.
SQL> create or replace package body some_pkg
2 as
3 procedure procedureA
4 as
5 l_list t_list;
6 begin
7 procedureB( l_list );
8 dbms_output.put_line( l_list.count );
9 end;
10
11 procedure procedureB
12 ( p_list OUT t_list )
13 as
14 begin
15 select ename
16 bulk collect into p_list
17 from emp;
18 end;
19 end;
20 /
Package body created.
SQL> exec some_pkg.procedureA;
16
PL/SQL procedure successfully completed.
另一种选择是在SQL中声明类型,即
SQL> create type t_list
2 as table of varchar2(10);
3 /
Type created.
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure procedureB( p_list OUT t_list )
2 as
3 begin
4 select ename
5 bulk collect into p_list
6 from emp;
7* end;
SQL> /
Procedure created.
SQL> create or replace procedure procedureA
2 as
3 l_list t_list;
4 begin
5 procedureB( l_list );
6 dbms_output.put_line( l_list.count );
7 end;
8 /
Procedure created.
SQL> exec procedureA;
16
PL/SQL procedure successfully completed.