Auto ID [message #110619] |
Wed, 09 March 2005 01:58 |
ys_chin
Messages: 4 Registered: March 2005
|
Junior Member |
|
|
After performing an insert statement into the parent table (Auto increment ID generated from trigger),
how to make sure that i am getting back the correct ID in order for me to perform insertion into child table?
|
|
|
Re: Auto ID [message #111148 is a reply to message #110619] |
Mon, 14 March 2005 05:38 |
Frank Naude
Messages: 4581 Registered: April 1998
|
Senior Member |
|
|
I don't quite understand your problem, but if you are using a sequence, you can always get the current value with something like this:
SELECT seqname.currval FROM dual;
INSERT INTO parent_table VALUES (seqname.nextval, ..
INSERT INTO child_table VALUES (seqname.currval, ...
Best regards.
Frank
|
|
|
Re: Auto ID [message #111160 is a reply to message #110619] |
Mon, 14 March 2005 06:29 |
ys_chin
Messages: 4 Registered: March 2005
|
Junior Member |
|
|
Thanks for helping...
My concern is actually after insert into the parent table,
there might be someone else inserted into parent table as well,
just before i inserted data into child table
INSERT INTO parent_table VALUES (seqname.nextval, ..
INSERT INTO parent_table VALUES (seqname.nextval, ..
INSERT INTO child_table VALUES (seqname.currval (wrong value), ...
What is the common practise to avoid this happen?
Thanks.
|
|
|
Re: Auto ID [message #111165 is a reply to message #111160] |
Mon, 14 March 2005 07:00 |
Frank Naude
Messages: 4581 Registered: April 1998
|
Senior Member |
|
|
Hi,
That is not a problem. CURRVAL will only return the last NEXTVAL value for your session. You don't have to worry about the other users at all.
Best regards.
Frank
|
|
|
|