Insert data from android app into Oracle SQL table then take auto generated id and insert that into another table

I have two tables stored in a Oracle database. One stores customer data such as name and address. I then have another table that holds a customers username and password and takes in the customer ID as a foreign key. I then have an Android app where users will be able to create new accounts. The difficulty I have is that say a user enters in there information and a username and password on tapping the submit button all there details need to be entered into the customer table. This will then generate an auto number ID with my trigger and sequence. I then need to retrieve this auto generated number and submit it along with the username and password into the username table. I this possible within SQL.

Views: 22

Reply to This

Replies to This Discussion

You can use the RETURNING CLAUSE in your insert command.

It should look like this:

INSERT INTO customer (col1, col2, ...) VALUES (val1, val2, ...) RETURNING id

Another option is to use the INSERT ALL syntax, something like this:

INSERT ALL   INTO customer (id, col1, col2, ...) VALUES (your_seq.nextval ,val1, val2, ...)   INTO customer_details (cust_id, col1, col2, ...) VALUES (your_seq.currval ,val1, val2, ...) select * from dual;

Reply to Discussion


Oracle Jobs in US

© 2023   Created by Maisam Agha.   Powered by

Badges  |  Report an Issue  |  Terms of Service