DBAsupport.com Forums - Powered by vBulletin
Results 1 to 6 of 6

Thread: ONE SMALL QUESTION

  1. #1
    Join Date
    Feb 2001
    Posts
    35

    Red face

    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,???????)

  2. #2
    Join Date
    Jul 2000
    Posts
    53
    Hi,

    Why don't you use the same sequence, currval for the detail table rather than nextval?

    Hope this helps
    Steve

  3. #3
    Join Date
    Feb 2001
    Posts
    35
    i didn't understand

  4. #4
    Join Date
    Mar 2000
    Location
    Atlanta, GA,USA
    Posts
    155
    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.

  5. #5
    Join Date
    Feb 2001
    Posts
    35
    When i do so PK of master table increments+1

    ex. 1,3,5,7,... instead of 1,2,3,4,...

  6. #6
    Join Date
    Nov 2000
    Location
    Baltimore, MD USA
    Posts
    1,339
    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
  •  


Click Here to Expand Forum to Full Width