如何在PL / SQL中用光标显示嵌套表的内容

时间:2012-06-12 15:54:25

标签: oracle plsql cursor nested-table

我想使用游标显示嵌套表的内容。我尝试了以下但它不起作用。 “put_line”中的参数不正确,但我不知道为什么。

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;

这很简单。一个孩子有一个名字和一个玩具清单,我想展示玩具,但不是从“选择”而是光标。

感谢您的帮助。

鲍勃

1 个答案:

答案 0 :(得分: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.