Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Best way to retrieve the last inserted id

483594Jan 17 2006 — edited Jan 17 2006
Hi,

I am using Oracle 9i and I would like to know what is the best way for retrieving the last inserted id from an insertion without having stored procedure.

I saw that this could be possible:
insert into ....; select sequence.currval from ...
but since I use it in a multi-threaded application (multiple threads can call this previous line almost at the same time within different database connection ojbects) I am not sure if the select sequence.currval will always returns the value used for its insert since another insert could have been executed between the insert and its select sequence.currval.

I also saw something as:
declare i number;
begin insert into auto_increment, ... values ... returning id into i;

is it possible with dynamic SQL to do this kind of call within ODP.NET?

Is there something else to do what I want?

Thanks,
Francis
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 14 2006
Added on Jan 17 2006
2 comments
29,948 views