Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: how to get value of auto-increment PK of row just inserted?

Re: how to get value of auto-increment PK of row just inserted?

From: Lothar Armbüster <lothar.armbruester_at_rheingau.netsurf.de>
Date: 9 Feb 2000 18:46:20 +0100
Message-ID: <1159.74T1038T11263393lothar.armbruester@rheingau.netsurf.de>


Otis Gospodnetic wrote at 09-Feb-00 17:13:29 on the subject Re: how to get value of auto-increment PK of row just inserted?:

[...]

>I'm still struggling with this issue a litte, though :(
>I need to make 2 INSERTs using COMMIT, like this:

>-- this row gets a PK from sequence
>INSERT INTO user_auth (username,password) VALUES ('u', 'p');

>-- this row has a FK that references the above PK
>INSERT INTO user_info (user_id,name) VALUES (????,'Name Here');

>COMMIT;
Hello Otis,
there are some approaches to that:

  1. You could so a "select seq_test.nextval from dual;" to get the new PK and then do the two inserts.
  2. With Oracle8i you have the option to use something like

   insert into tab_test values (seq_test.nextval,...) return pk into    var_test;

   insert into tab_test2 values(var_test,...);

   That means you can get an insert to return some value into a variable.    Please check the manual for the exact syntax since I don't have it at    hand right now.

Hope that helps,
Lothar

--

Lothar Armbrüster       | lothar.armbruester_at_rheingau.netsurf.de
Hauptstr. 26            | lothar.armbruester_at_t-online.de
D-65346 Eltville        |

Received on Wed Feb 09 2000 - 11:46:20 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US