last_insert_id oracle

Asked

Viewed 139 times

1

I have a question about oracle bank.

I created two tables and put one of them with a field with foreing key (see below the FK)

tbl_city *id_city* (PK and auto increment) - generated with Quenquence, since we do not have auto_increment in oracle

municipality

tbl_schools Cod (PK)

school

*id_city (FK)*

How the hell do I mount an INSERT to popular the two tables? Up to hj I only mounted Insert’s for UMA tables on oracle.

1 answer

2


Use the RETURNING clause in your INSERT command:

INSERT INTO tbl_city (...) VALUES (...) RETURNING id_city INTO var_id;

and then use var_id in the INSERT table tbl_schools.

  • Like this? http://pastebin.com/ZKU9cbut#

  • It worked, thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.