2014-04-12 42 views
0

我是新來的,想要學習pl sql編程。在pl-sql中插入二維數組中的值

我們如何使用plsql程序在二維數組中插入數據。我能夠在1D數組中插入數據,但是我在將數據插入二維數組時遇到了問題。

declare 
    type type1 is table of number; 
    type data_type is table of type1; 
    y data_type; 
begin 
    y := data_type(); 
    y.extend(20000); 
    for i in 1..100 loop 
    for j in 1..100 loop 
     y(i)(j) := i+j; 
    end loop; 
    end loop; 
end; 

任何信息或提示將有所幫助。

回答

1

您初始化和擴展外陣列y,但你也需要初始化和擴展每個子陣列y(i)

declare 
    type type1 is table of number; 
    type data_type is table of type1; 
    y data_type; 
begin 
    y := data_type(); 
    y.extend(100); 
    for i in 1..100 loop 
    y(i) := type1(); 
    y(i).extend(100); 
    for j in 1..100 loop 
     y(i)(j) := i+j; 
    end loop; 
    end loop; 
end; 
/

上面的代碼成功運行對我的Oracle XE數據庫11gR2的。