我在 PL/SQL 包中创建了一个函数,该函数使用定义为数字表的自定义类型。我在带有 SELECT COLUMN_VALUE 指令的 SQL 查询中使用这种类型的对象,如下所示:
包中的类型定义:
type T_IDS is table of my_table.col_id%type;
包体中一个过程内的查询:
l_ids_list T_IDS ;
begin
select col_ids bulk collect into T_IDS from my_table;
select sum(t.rec_value) into total_value
from my_table t where t.col_id in (
select column_value from Table(l_ids_list) );
一切正常,当我编译这段代码时,我可以看到在我的 schema_name/type 部分下生成了一个新类型。
一旦我在测试环境中安装了它,它就会导致编译失败并出现错误:
错误:PLS-00642:SQL 语句中不允许本地集合类型
错误:PL/SQL:ORA-22905:无法访问非嵌套表项中的行
数据库版本(本地和测试)完全相同,11g。有没有办法在 DBMS 上激活这样的一代?
重现的例子:
create table my_table (
col_id number,
rec_value number
);
insert into my_table (col_id, rec_value) values (1,100);
insert into my_table (col_id, rec_value) values (2,200);
insert into my_table (col_id, rec_value) values (3,300);
insert into my_table (col_id, rec_value) values (4,400);
commit;
包创建:
create or replace package test_pck as
type T_IDS is table of my_table.col_id%type;
procedure test_list;
end test_pck;
/
create or replace
package body test_pck as
procedure test_list is
l_ids_list T_IDS ;
total_value number;
begin
select col_id bulk collect into l_ids_list from my_table;
select sum(t.rec_value) into total_value
from my_table t where t.col_id in (
select column_value from Table(l_ids_list) );
end test_list;
end test_pck;
/