Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to write stored procedure for inserting into many to many relationships

user8816970Mar 17 2013 — edited Mar 22 2013
I have two tables: User and Project each with a integer PK of "id" and single data field of "name".
I have created a junction table ProjectsUsers that implements the many to many relationships between Users and Projects.

Can someone help me write a stored procedure to, given a User.id and a new project name, create a new row in the project table and update the junction table appropriately so it is owned by the user.

(1) I assume we want to start a new transaction
(2) What failures could occur that would cause me to want to roll back the transaction?
(3) How do I detect failures that would cause me to roll back the transaction? Do I check a global variable for errors? Or do I assume the insert statement will throw an exception I can catch?
(4) How do I get the id of the newly created project row and return it back to the calling program?
(5) How do I communicate to the calling program that the transaction failed and must be tried again?
Thanks
Siegfried
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 19 2013
Added on Mar 17 2013
3 comments
797 views