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

6
  • 2
    an Oracle SQL question without SQL code is not a nice question. At first glance I would say a TRIGGER Commented May 4, 2017 at 9:23
  • Sorry, I will try to write an example Commented May 4, 2017 at 9:24
  • 1
    This might can help you: allthingsoracle.com/multi-table-insert-statements-in-oracle Commented May 4, 2017 at 9:24
  • Something like that @ThomasG Commented May 4, 2017 at 9:42
  • 1
    Please try and search before asking questions, even just this site. stackoverflow.com/questions/5814323/… Commented May 4, 2017 at 14:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.