In SQLServer, it is generally believed that adding SELECT SCOPE_IDENTITY () at the end of your insert is the best way to return the PK of a newly inserted record, assuming you use an auto-increment field for pk.
However, I cannot find an equivalent for Oracle.
It is best practice to use a sequence to generate PK, but there are various options for implementing this. Do you leave it to the developer to insert sequence.nexval or with a trigger?
In any case, getting a new ID response seems like a common problem.
Suggestions and solutions that I came across include:
- creating a stored procedure that returns PK
- running select select identifier from seq.nextval and then passing it to insert
- select max (id) after insertion (Note: do not do this!)
- add the RETURNING clause to the insert
What should be the โbest practiceโ solution for this situation?
chris
source share