sql - BULK COLLECT into table of objects inside LOOP? -
this have done untill now. created object , table of objects.
create type my_obj object(    val1      varchar2(30),    val2     varchar2(30),    val3      varchar2(30));  create type table_obj table of my_obj; inside procedure this:
procedure myproc(     tableobj                          out     table_obj,      mycursor                          out     otherpck.refcursor,     ...other in param)  --other code inside loop need query , gives 3 varchar2 values output on each iteration (i.e. val1, val2, val3) , need store them in tableobj , after query table put of results on ref cursor, so:
 begin      in somethingelse loop   select my_obj(val1, val2, val3) bulk collect tableobj  ...  ...  endloop;   open mycursor select * table(tableobj); the code compiles without problems 1 row in mycursor , surely there more one. have tried also:
select val1, val2, val3 tableobj but get:
pl/sql: ora-00947: not enough values how can put each result of select (always 1 row of these 3 varchar2) , save tableobj?
the answer specific question this, given select inside loop returns 1 row:
declare   obj my_obj;   tableobj table_obj := table_obj(); -- initialise collection begin      in somethingelse loop   select my_obj(val1, val2, val3) obj  ...  ...     tableobj.extend();    tableobj(tableobj.count) := obj;  endloop;   open mycursor select * table(tableobj); however, feel sure possible rewrite query avoid loop altogether:
begin       select my_obj(val1, val2, val3) bulk collect tableobj  ...  ... in (select ... somethingelse)   open mycursor select * table(tableobj); but it's hard sure without knowing more , somethingelse!
Comments
Post a Comment