我在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部分下生成的新类型。
一旦我将它安装在测试环境中,失败与错误编译:
Error: PLS-00642: local collection types not allowed in SQL statements
Error: PL/SQL: ORA-22905: cannot access rows from a non-nested table item
数据库版本(本地和测试)是完全一样的,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;
/
你的意思是这两个数据库是11.2,即SELECT * FROM V $版本一样?你是在测试中编译过的,还是由Dev的export/import创建的? – 2013-01-24 12:14:18
在检查不同版本之后,不编译的版本是版本11.2.0.3,其中编译版本是11.2.0.1版本。源代码直接在数据库上编译,并且未安装导出文件 –