-
I insert one record in master table.
After that i must insert record in detail table,
but in insert statement i must know what is the value of PK
of master record.
All id's in master and detail tables are make with sequences
ex:
master table: 111.aaa(PK),222.aaa,333.aaa
detail table: 111.bbb(PK),222.bbb(FK<---111.aaa)
1) insert into aaa values (222.aaa,333.aaa)
2) insert into bbb values (111.bbb,???????)
-
Hi,
Why don't you use the same sequence, currval for the detail table rather than nextval?
Hope this helps
Steve
-
-
1) SQL
insert into aaa values (sequence.nextval,222.aaa,333.aaa);
insert into bbb values (111.bbb,sequence.currval);
2) PL/SQL
declare
temp number;
begin
select sequence.nextval
into temp
from dual;
insert into aaa values (temp,222.aaa,333.aaa);
insert into bbb values (111.bbb,temp);
commit;
end;
/
Enjoy...
Sergey.
-
When i do so PK of master table increments+1
ex. 1,3,5,7,... instead of 1,2,3,4,...
-
Re-check your code against that of the posted solution. Make sure that the one line says .NEXTval and the other says .CURRval. The sequence will *only* increment when you make the .NEXTval method call.
- Chris
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|