Error ORA-06531: Reference to uninitialized collection

0

They could help me know what the problem with my program is ... I have this code inside a package:

TYPE t_rec IS RECORD(t_id INTEGER,t_text VARCHAR2(40));
TYPE t_recs IS TABLE OF t_rec;

FUNCTION test_func RETURN tp_recs PIPELINED AS 
currec t_recs;
cur    t_rec;
reg number := 0;
BEGIN

for reg in 1..10 loop

  currec(reg).tt_id   := reg;
  currec(reg).tt_text := 'test '||reg;
end loop;

for reg in currec.first .. currec.last loop

  cur.tt_id   := currec(reg).tt_id;
  cur.tt_text := currec(reg).tt_text;

  pipe row(cur);
end loop;

END;

When I make a select on the function, it throws me the error.

SELECT * 
FROM TABLE( test_pkg.test_func());
  

ORA-06531: Reference to uninitialized collection

    
asked by el_perrito 12.04.2017 в 19:33
source

1 answer

0

You need to initialize the object you are returning tp_recs before filling it with information.

    
answered by 25.05.2017 в 05:54