我想将表类型作为参数传递给过程。
create or replace package FOO is
type FOOTYPE is record (
FOOTYPE_A varchar2(5) null,
FOOTYPE_B varchar2(5) null,
FOOTYPE_C varchar2(5) null
);
type FOOTYPETABLE is table of FOOTYPE;
...
procedure sendNew (
table_a in FOOTYPETABLE
) is
a number;
begin
...
end sendNew;
...
end FOO;
declare
type bartabletype is table of FOO.FOOTYPE index by binary_integer;
bartable bartabletype;
begin
bartable(0).FOOTYPE_A := '';
bartable(0).FOOTYPE_B := '';
bartable(0).FOOTYPE_C := '';
bartable(1).FOOTYPE_A := '';
bartable(1).FOOTYPE_B := '';
bartable(1).FOOTYPE_C := '';
FOO.sendNew(bartable);
end;
但甲骨文说:
" ora-00306错误的数字或类型的参数"。
为什么?
答案 0 :(得分:5)
当你期望pl / sql表(嵌套表)时,你试图传入一个关联数组(索引)。例如,执行以下操作:
create or replace package tpkg as
type t_myrec is record (
val1 varchar2(1000),
val2 varchar2(1000)
);
type t_myrec_tab is table of t_myrec;
procedure recv_ary(i_ary in t_myrec_tab);
end;
create or replace package body tpkg as
procedure recv_ary(i_ary in t_myrec_tab) is
begin
-- do something here
dbms_output.put_line('Array has ' || i_ary.count || ' elements');
end;
end;
并使用它:
declare
some_ary tpkg.t_myrec_tab;
begin
select object_name, object_type
bulk collect into some_ary
from user_objects
where rownum <= 100;
tpkg.recv_ary(some_ary);
end;
注意我将“some_ary”声明为“tpkg.t_myrec_tab”类型。换句话说,我特意引用了包类型,所以我知道它正确的集合类型。
答案 1 :(得分:0)
这可能是因为FOOTYPETABLE
被声明为过程sendNew()参数类型,它与您尝试传递给它的table of FOO.FOOTYPETABLE
不同。
答案 2 :(得分:0)
bartable
变量必须是FOO.FOOTYPETABLE
类型,而不是bartabletype