How to get the record ID of a newly inserted record

Hi,

I insert a record in a table wich have an auto-increment ID column. I want to retrieve the newly inserted record by reading the generated ID.

I"m using Oracle 10g. What is the best way to do this? I'm looking for something similar than @@Identity in SQL Server.

Thanks
pmaltaisAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
sdstuberConnect With a Mentor Commented:
use the RETURNING clause

assuming you have a table my_table(id number, x number, y number, z number) with a trigger populating the id column via sequence, try this...


insert into my_table (x,y,z) values (1,2,3) RETURNING id INTO v_id_value;
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
in oracle, the "identity" is translated into a sequence object, eventually combined with a trigger:
http://www.techonthenet.com/oracle/sequences.php
http://www.databaseanswers.org/sql_scripts/ora_sequence.htm
0
All Courses

From novice to tech pro — start learning today.