Solved

How to get the record ID of a newly inserted record

Posted on 2009-07-06
2
719 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
2 Comments
 
LVL 73

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 142

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Note: You must have administrative privileges in order to create/edit Roles. Salesforce.com (http://www.salesforce.com/) (SFDC) is a cloud-based customer relationship management (CRM) system. It is a database most commonly used by sales and marke…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now