2011-11-07 31 views
0

在下面的代碼示例,PL/SQL二維陣列 - 不能得到第2項

Type single_table_purge_type is varray(2) of varchar2(255); 
Type single_table_list is table of single_table_purge_type; 

purge_table single_table_list; 

purge_table := new single_table_list(
      new single_table_purge_type('product','Where product_id=5'), 
      new single_table_purge_type('customer','Where customer_id=10') 
); 

For x in 1..purge_table.Count 
     Loop 
      For y in 1..purge_table(x).Count 
      Loop 
       DBMS_OUTPUT.put_line('x='||x||' y='||y||' cell='||purge_table(x)(y)); 
      End loop; 
     End loop; 

DBMS_OUTPUT.put_line('m1 ' || purge_table(1)(1)); 
DBMS_OUTPUT.put_line('m2 ' || purge_table(1)(2)); 
DBMS_OUTPUT.put_line('m3 ' || purge_table(2)(1)); 
DBMS_OUTPUT.put_line('m4 ' || purge_table(2)(2)); 

我怎樣才能前項(1,2)或(2,2)? (即where子句)。 所有我看到的是第一個項目的副本,當我打印出的值。

輸出

m1 product 
m2 product 
m3 customer 
m4 customer 
+0

能否請你告訴我們,你做了正確的SQL?謝謝。 – Jemru

回答

1

運行你的代碼所示(添加declarebeginend),我得到以下上的Oracle 10g:

x=1 y=1 cell=product 
x=1 y=2 cell=Where product_id=5 
x=2 y=1 cell=customer 
x=2 y=2 cell=Where customer_id=10 
m1 product 
m2 Where product_id=5 
m3 customer 
m4 Where customer_id=10 

這使我相信,有你裝配你給我們展示的作品的方式出了問題。請編輯您的問題,以提供與運行時完全相同的腳本。

(這確實應該是一個評論,但它需要的長度,並且將不適合那裏的格式。)

+0

我實際上在創建集合時使用了一個函數,並且它返回了錯誤的值。謝謝 – ziggy