I would like to get ROWID of inserted record using RETURNING clause from FORALL INSERT statement (bulk insert) back into pl/sql table of records (associative array of records). I believe, that problem is in using table of records in FORALL and BULK COLLECT together.
See the example:
CREATE TABLE test2 (num NUMBER);
set serveroutput on
DECLARE
TYPE r_rec IS RECORD (num NUMBER, row_id ROWID);
-- TYPE t_rid IS TABLE OF rowid INDEX BY BINARY_INTEGER;
TYPE t_tab IS TABLE OF r_rec INDEX BY BINARY_INTEGER;
v_tab t_tab;
--v_rid t_rid;
BEGIN
v_tab(1).num := 1.11;
v_tab(2).num := 2.22;
v_tab(3).num := 3.33;
--
FORALL i IN v_tab.first..v_tab.last
INSERT INTO test2 (num)
VALUES (v_tab(i).num)
RETURNING rowid BULK COLLECT INTO v_tab(i).row_id
;
FOR i IN v_tab.first..v_tab.last
LOOP
dbms_output.put_line('num/rowid : ' || v_tab(i).num || '/' || v_tab(i).row_id);
END LOOP;
END;
/
It raises error: PLS-00437: FORALL bulk index cannot be used in RETURNING clause Where is a problem here? Do I need another PL/SQL table for returning ROWIDs?