【问题标题】:PL SQL table parameterPL SQL 表参数
【发布时间】:2013-06-12 14:05:32
【问题描述】:

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

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

为什么?

【问题讨论】:

    标签: oracle plsql types


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-04-15
          • 2018-06-19
          • 2014-02-17
          • 1970-01-01
          相关资源
          最近更新 更多