Suppose I have the following two tables in my Oracle database:
create table a (num number);
create table b (val varchar2(30);
and in my PL/SQL program I have declared a nested collection as follows:
declare
-- type for inner collection; shadows table b
type inner_tab_t is table of varchar2(30);
-- record type for outer table
type outer_tab_rec is record
(
num number,
vals inner_tab_t
);
-- type for outer table
type outer_tab_t is table of outer_tab_rec;
-- actual inner_tab_t
inner_tab inner_tab_t;
-- actual outer_tab_t
outer_tab outer_tab_t;
I am wondering whether it is possible to use a FORALL statement to insert the data from outer_tab into both tables a and b?
In other words, given the following assignments:
begin
inner_tab := inner_tab_t('one', 'two', 'three');
outer_tab := outer_tab_t();
outer_tab.extend;
outer_tab(outer_tab.last).num := 1;
outer_tab(outer_tab.last).vals := inner_tab;
I'd like to do something like this (obviously doesn't work):
forall ind in outer_tab.first .. outer_tab.last
insert into a (num)
values(outer_tab(ind).num)
forall ind2 in outer_tab(ind).vals.first .. outer_tab(ind).vals.last
insert into b (val)
values (outer_tab(ind).vals(ind2);
Is there a convenient way of handling such a situation?

FORALLfor outer_tab ? – Phil Aug 14 '12 at 18:39indfrom aforallanywhere except INSERT/UPDATE/DELETE, therefore makingforallnot nestable in this situation. A loop instead offorallforouter_tabwould work. I suspect you already knew this :) – Phil Aug 14 '12 at 18:46