1

I know about inserting into multiple tables.

But I was wondering if anyone know if there is a way to use the returning values from the first table with the insert in the other table in this multiple table insert?

insert all
into table1 (col1, col2, col3) values (param1, param2, param3)
into table2 (col4, col5, col6) values ([table1.returning_id], param5, param6)
select * from source_table;

I could solve it with

for l_row in l_source_table_cursor loop
  insert into table1 (col1,col2,col3)
  values (param1,param2,param3)
  returning table1_id into l_table1_id;

  insert into table2(col4,col5,col6)
  values (l_table1_id, l_row.param5, l_row.param6);
end loop;

But I was wondering if its possible to do it with a multiple table insert statement

Moptan
  • 326
  • 1
  • 11

0 Answers0