Best way to retrieve the last inserted id
483594Jan 17 2006 — edited Jan 17 2006Hi,
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