Solved

How to get the record ID of a newly inserted record

Posted on 2009-07-06
2
723 Views
Last Modified: 2013-12-19
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
0
Comment
Question by:pmaltais
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 125 total points
ID: 24784920
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
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24784923
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Read about achieving the basic levels of HRIS security in the workplace.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question