0

我想将表类型作为参数传递给过程。

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 参数数量或类型错误”。

为什么?

4

3 回答 3

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”类型。换句话说,我专门引用了包类型,所以我知道它是正确的集合类型。

于 2013-06-12T14:34:59.127 回答
0

bartable 变量必须是类型FOO.FOOTYPETABLE而不是bartabletype

于 2013-06-12T14:37:07.923 回答
0

这可能是因为FOOTYPETABLE声明为过程 sendNew() 参数类型的 与table of FOO.FOOTYPETABLE您尝试传递给它的 不同。

于 2013-06-12T14:25:40.273 回答