Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle - return newly inserted key value

We have a table with a Primary Key that gets populated on insert by a trigger on the table - the trigger gets the next sequence number from a sequence we created for the table and uses that for the value of the key on insert. Now we would like to be able to return that value in our insert procedure (PL\SQL), similar to select @@scope_identity in SQL Server. I have been googling all day and basically come up with nothing - anyone been successful with this before?

Thanks

like image 652
Jim Evans Avatar asked Jul 17 '09 19:07

Jim Evans


1 Answers

I don't know if it works with triggers but the RETURNING clause may be what you're looking for:

INSERT INTO my_table (col_1, col_2)
  VALUES ('foo', 'bar')
  RETURNING pk_id INTO my_variable;
like image 67
Ken Keenan Avatar answered Oct 03 '22 07:10

Ken Keenan