【问题标题】:How to show content of a nested table with a cursor in PL/SQL如何在 PL/SQL 中使用游标显示嵌套表的内容
【发布时间】:2012-06-12 15:54:25
【问题描述】:

我想使用游标显示嵌套表格的内容。我尝试了以下方法,但它不起作用。 “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;

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

感谢您的帮助。

鲍勃

【问题讨论】:

    标签: oracle plsql cursor nested-table


    【解决方案1】:

    需要在循环中引用列名

    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.
    

    【讨论】:

    • 感谢您的回答和快速回复。
    猜你喜欢
    • 2014-04-01
    • 2020-04-01
    • 2018-01-12
    • 1970-01-01
    • 1970-01-01
    • 2013-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多