2个问题 谢谢各位GGMM了
 
关于嵌套表中不能存多行记录问题
Oracle 版本 10g
First:
create or replace type tt as object(
  g_id number(6),
  g_name varchar(20),
  g_name varchar(20)
)create or replace type tt_type is table of tt;delcare
  test_tt_type tt_type;
begin  
 select * bluk collect into test_tt_type from goods//表goods的结构与 定义的 tt类型一致
end;错误信息: 没有足够的值
这说明嵌套表不能存多个值吗?
如果我改为用pl/sql表类型就可以
delcare
  type tt_type is table of goods%rowtype index by binary_Integer;
  test_tt_type tt_type;
begin  
 select * bluk collect into test_tt_type from goods//表goods的结构与 定义的 tt类型一致
end;这样是没有问题的,有点费解。。Second:
关于用for in 打开游标问题
declare
cursor test is select * from goods;
begin
for i in test
 dbms_output.putline(i.g_id);
end;
这是正常的,但是我一旦使用游标标量就出问题了declare
type test_type is ref cusor;
cur_test_type test_type;
begin
open cur_test_type for select * from goods;
for i in cur_test_type
 dbms_output.putline(i.g_id);
end;
这就出问题了。。

解决方案 »

  1.   

    declare
    type test_type is ref cusor;
    cur_test_type test_type;
    begin
    open cur_test_type for 'select * from goods';
    for i in cur_test_type
     dbms_output.putline(i.g_id);
    end;
      

  2.   

    第一个问题:
    goods表字段个数及类型与你定义的类型tt完全一致吗?
      

  3.   

    open cur_test_type for 'select * from goods';
     忘记打“”,失误。
      希望第一个问题能有人继续解
      

  4.   

    First:
    create or replace type tt as object(
      g_id number(6),
      g_name varchar(20),
      g_name varchar(20)
    )create or replace type tt_type is table of tt;delcare
      test_tt_type tt_type;
    begin   
     select * bluk collect into test_tt_type from goods;//表goods的结构与 定义的 tt类型一致
    end;的确回报楼主说的一样异常信息。我也测试了很长时间都这样!
    最后我想,因为你的test_tt_type是一个存放tt对象的表,但你的select * bluk collect into test_tt_type from goods语句查询出来的列不是一个对象(而是number和varchar2的两列值),所以不能够存放到test_tt_type表中,如果真的要存放到test_tt_type表中我想先要‘new’一个tt对象,然后对tt对象的各个属性赋值(我用java中的方法):tt.g_id=id;tt.g_name=name;然后再把tt放到test_t_type嵌套表中。
    (我猜这个可能就想java中的对象一样,你在使用对象前必须初始化一个对象)
      

  5.   

    http://cn.forums.oracle.com/forums/thread.jspa?messageID=4013077
    给个链接,可以看看。我也是从这个帖子得到的启发!
    如果我理解有误,请原谅!