2013-03-06 107 views
2

我有以下類型定義成包PLSQL未初始化的集合

type column_info is record (col_name varchar2(20), col_value varchar2(1000)); 
type c_info is varray(10) of column_info; 
type table_info is record (table_name varchar2(20), col_info c_info); 

的規格在聲明部分封裝體我在包裝體的主體我有

t_info table_info; 

在過程內部的

t_info:=null; 
t_info.table_name:='gl_temp_report1'; 
t_info.col_info(1).col_name:='table_idx'; 
t_info.col_info.extend; 
t_info.col_info(2).col_name:='table_row'; 
t_info.col_info.extend; 
t_info.col_info(3).col_name:='table_row_detail'; 

偶數包編譯成功,在運行時我得到異常ORA-06531:Re對未初始化的收集。
我如何初始化col_info集合? 我試圖初始化t_info.col_info(),但我得到了「沒有功能」像這樣。 TIA,Aurel

+0

http://ora-06531.ora-code.com/並閱讀帖子底部,這可能會幫助你。 – 2013-03-10 04:16:39

回答

3

您應該在訪問它們之前正確初始化所有集合(包括嵌套)。
它們在初始化之前是原子上的空值。

t_info := table_info('gl_temp_report1', c_info()); 

您還必須調用extend每個VARRAY元素賦值之前(或​​一次延長)。
還是做這一切在一個聲明:

t_info := table_info('gl_temp_report1', c_info('table_idx','table_row','table_row_detail')); 
+0

我得到了「這個範圍內沒有名稱爲'TABLE_INFO'的函數 – user1540471 2013-03-06 19:36:52

+0

@ user1540471 - 對不起,我忘記了與對象不同的記錄,沒有方便的構造函數,記錄的每個字段都應該單獨初始化't_info .table_name:='gl_temp_report1';''''和't_info.col_info:= c_info();' – 2013-03-06 20:43:02

3

要執行初始化,您需要一個初始化塊添加到包體,在類似如下的方式:

CREATE OR REPLACE PACKAGE BODY your_package IS 
    t_info table_info; 

    -- Whatever other procedure definitions, etc, are needed 

BEGIN -- package initialization 
    t_info.table_name:='gl_temp_report1'; 
    t_info.col_info := c_info(); 
    t_info.col_info.extend; 
    t_info.col_info(1).col_name:='table_idx'; 
    t_info.col_info.extend; 
    t_info.col_info(2).col_name:='table_row'; 
    t_info.col_info.extend; 
    t_info.col_info(3).col_name:='table_row_detail'; 
EXCEPTION 
    WHEN OTHERS THEN 
    DBMS_OUTPUT.PUT_LINE('Exception!'); -- Add whatever error handling is needed 
END your_package; 

分享享受。

0

如圖所示,您可以創建T_Info中

declare 
type column_info is record (col_name varchar2(20), col_value varchar2(1000)); 
    type c_info is varray(10) of column_info; 
    type table_info is record (table_name varchar2(20), col_info c_info); 
    t_info table_info; 
begin 
    t_info.table_name := null; 
    t_info.col_info := c_info(); 
    for i in 1..10 loop 
    t_info.col_info.extend; 
    t_info.col_info(i).col_name := null; 
    t_info.col_info(i).col_value := null; 
    end loop; 
end; 
/

乾杯!

+0

這不起作用,存在語法錯誤,這些構造函數不能與RECORD一起使用。 – 2014-04-26 07:30:57