Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: How to get the ID of the last inserted row
Daniel Morgan wrote:
> Richard Kuhler wrote:
>
>> Daniel Morgan wrote: >> <snip> >> >>>> I was referring to the possibility that a trigger could select >>>> another value from the sequence between the time the value for the >>>> insert is selected and your currval select. In that situation you >>>> won't get the value you're probably expecting. >>>> >>>> >>>> Richard Kuhler >>>> >>> Of course you will. You always get back the last value from your own >>> session. Oracle is not a single-user database. >> >> >> >> I guess I should have been clearer there. I'm referring to a trigger >> firing IN THE SAME SESSION that may use the sequence a second time >> within the duration of what the application perceives to be a single >> insert. >> >> >> Richard Kuhler
I'm not suggesting that CURRVAL doesn't do what it should only that the developer is making an assumption that it's is the behavior they want. Ok, let me explain this step by step and see if I can get you to see the problem ...
... all is well, there is order in the universe ...
6. A new additional trigger is born (let's call it TRIG2) that inserts an additional row into the table T for each insert statement (no it's not mutating at the statement level) and hence needs to get another value from sequence S using S.NEXTVAL.
... the CURRVAL usage in procedure P is now broken for a logical standpoint. Instead of getting the value it's expecting (the ID of the row that it inserted on the line immediately preceding it) it now gets the ID of the additional row inserted by trigger TRIG2.
Richard Kuhler Received on Wed Oct 01 2003 - 13:22:41 CDT
![]() |
![]() |