2012-06-12 54 views
0

我想使用遊標顯示嵌套表的內容。我嘗試了以下,但它不起作用。 「put_line」中的參數不正確,但我不知道爲什麼。如何使用PL/SQL中的遊標顯示嵌套表的內容

create or replace type toys_t as table of varchar2(40); 

create or replace type kid_t as object (name varchar2(10), toys toys_t); 

create table kid of kid_t nested table toys store as table_toys; 

insert into kid values('Bob', toys_t('truck','ball','doll')); 

select t.* from kid k, table(k.toys) t where k.name = 'Bob'; 


declare 

cursor cursor_table is 
    select t.* from kid k, table(k.toys) t where k.name = 'Bob'; 

begin 

    for i in cursor_table loop 
     dbms_output.put_line(i); 
    end loop; 

end; 

這很簡單。一個孩子有一個名字和一個玩具清單,我想顯示玩具,但不是來自「選擇」,而是一個光標。

感謝您的幫助。

鮑勃

回答

2

您需要在循環

SQL> ed 
Wrote file afiedt.buf 

    1 declare 
    2 cursor cursor_table is 
    3  select t.* from kid k, table(k.toys) t where k.name = 'Bob'; 
    4 begin 
    5  for i in cursor_table loop 
    6  dbms_output.put_line(i.column_value); 
    7  end loop; 
    8* end; 
SQL>/
truck 
ball 
doll 

PL/SQL procedure successfully completed. 
+0

謝謝您的回答,快速回復引用列名。 –