首页 > 解决方案 > 在包中定义集合类型

问题描述

在模式级别创建集合类型时,此测试包编译良好:

create type table_of_ids as table of number;

create or replace package test_package as
    procedure test_p(my_input table_of_ids);
end;

create or replace
    package body test_package as

    procedure test_p(my_input table_of_ids) as
        res_tab table_of_ids;
    begin
        select res_id bulk collect
          into res_tab
          from test_table
         where id in (select column_value from table (my_input));
        null;
    end test_p;

end test_package;

但是当我尝试在包中定义集合类型时,它失败了:

create or replace package test_package as
    type my_table is table of number;
    procedure test_p(my_input my_table);
end;

create or replace
    package body test_package as

    procedure test_p(my_input my_table) as
        res_tab my_table;
    begin
        select res_id bulk collect
          into res_tab
          from test_table
         where id in (select column_value from table (my_input));
        null;
    end test_p;

end test_package;

我收到的消息是:

Error(8,5): PL/SQL: SQL Statement ignored
Error(8,107): PL/SQL: ORA-22905: cannot access rows from a non-nested table item
Error(8,113): PLS-00642: local collection types not allowed in SQL statement

那么,这是否意味着我不能只在包中定义这种类型?或者我错过了什么?

标签: oracleplsql

解决方案


推荐阅读