Solved

How to get the record ID of a newly inserted record

Posted on 2009-07-06
2
724 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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

"Disruption" is the most feared word for C-level executives these days. They agonize over their industry being disturbed by another player - most likely by startups.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

752 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