我在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版本。源代碼直接在數據庫上編譯,並且未安裝導出文件 –