Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: get id after insert

Re: get id after insert

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Wed, 22 Dec 1999 07:02:33 -0500
Message-ID: <gbf16sodvhsgu9tgta6go46op3qa1vdtpk@4ax.com>


A copy of this was sent to buurd_at_my-deja.com (if that email address didn't require changing) On Wed, 22 Dec 1999 10:45:56 GMT, you wrote:

>That would do in a one-user enviorment but not in a multiuser.. since
>someone could do a new insert and then i would not get the number from
>my insert.
>

No, it would work and is exactly what currval is for.

currval is local to a session. it returns YOUR sessions last number generated by using NEXTVAL. prior to your sessions calling NEXTVAL -- currval is undefined.

This one the way to get the last value you inserted with sequence. The other is to use

insert into t ( id, c1, c2, c3, ... ) values ( my_seq.nextval, x1, x2, x3, ... ) returning id into :my_local_variable;

>Regards
>Roland
>
>In article <38605B79.976FA232_at_cig.nml.mot.com>,
> Troy Tinnes <q10641_at_cig.nml.mot.com> wrote:
>> Is the ID sequence generated? If so, you can do this:
>>
>> SELECT id.CURRVAL
>> FROM dual;
>>
>> - Troy
>>
>> buurd_at_my-deja.com wrote:
>>
>> > Hi!
>> > I'd often have to get the id (triggergenerated) from a table for the
>> > row i just inserted. I'd hope there is a better solution than asking
>> > for the max(id).
>> >
>> > Tia
>> >
>> > --
>> > Roland Carlsson
>> > Certified Java programmer
>> > Sk=F6vde
>> > Sweden
>> >
>> > Sent via Deja.com http://www.deja.com/
>> > Before you buy.
>>
>>

--
See http://osi.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'... Current article is "Part I of V, Autonomous Transactions" updated June 21'st  

Thomas Kyte                   tkyte_at_us.oracle.com
Oracle Service Industries     Reston, VA   USA

Opinions are mine and do not necessarily reflect those of Oracle Corporation Received on Wed Dec 22 1999 - 06:02:33 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US