該類型需要在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.
謝謝你的建議。 只是最後一個問題,說我知道確切的列表(示例名稱的靜態列表),使用TABLE VARCHAR2類型與Vararray的優點是什麼? – help
@help - 如果您知道集合將包含的元素數量,並且該數字永遠不會改變,那麼使用嵌套表格而不是VARRAY沒有任何優勢。但是,由於嵌套表的大小並不固定,因此當將來靜態列表不可避免地發生變化時,嵌套表會更加靈活。 –
嘿,謝謝。 – help