Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Row ID of last inserted or updated record

Status
Not open for further replies.

Fred12345

IS-IT--Management
Nov 29, 2002
1
GB
Migrating from SQL Server to Oracle. SQL Server Stor Proc
as follows...

Insert Into Table1
(field1, field2,...)
Values (a, b, ...)

Select @@Identity as "Identity"

@@Identity is a global variable which returns the
identity (or row id) of the last inserted record.

What is the equivalent way in Oracle to do the same
thing? Thanks for any replies.
 
Oracle insert statements allow one to specify a "returning" clause and store the resulting info in a pl/sql variable. The code to return a rowid would look something like

insert into your_table values (insert values here)
returning rowid into :rowid_var;

The rowid will be 18 characters long.
 
However, ROWID can change over time. If you are using the RETURN mechanism, whatever you are using for a Primary Key might be a better choice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top