Amit
Amit

Reputation: 623

How to get the PK_ID of the last inserted row in oracle?

I have a scenario where I have to return the pkId of the row which is inserted into the db recently. But i am afraid there is no straight way to achieve it in Oracle. Can any one tell any way to do it?

Upvotes: 1

Views: 329

Answers (1)

OMG Ponies
OMG Ponies

Reputation: 332691

Assuming 10g+, use the RETURNING clause:

INSERT INTO YOUR_TABLE
  (columns...)
VALUES
  (...)
RETURNING <expression> INTO <variables>

For more info, see:

Upvotes: 5

Related Questions