Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Auto-incrementing primary key?
In article <34BE598E.7468_at_lilly.com>, Ed Bradt <ebradt_at_lilly.com> writes
>S Metro wrote:
>>
>> I also have the same dillemma. That solution sounds great, but what if
>> after inserting the row, you immediately need the value of the key. Since
>> the trigger used the NEXTVAL, can a user get the CURRVAL to find out what
>> was inserted?
>>
[snip]
>
>Sure the user can get CURRVAL but there's no guarantee that someone else
>hasn't made another hit on the sequence in between. If you need to know
>what the key value is for further access to that same record then select
>and save myseq.nextval and use the saved value in the insert and
>subsequent queries for that row.
>Ed
The currval refers to the current session, so a nextval followed by a currval will always be correct.
Andy
-- Andy Hardy. PGP key available on request ===============================================================Received on Wed Jan 21 1998 - 00:00:00 CST