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

Home -> Community -> Usenet -> c.d.o.misc -> Re: How do I retrive newly added records?

Re: How do I retrive newly added records?

From: Ralph Ganszky <ralph.ganszky_at_sap-ag.de>
Date: Sun, 02 May 1999 10:56:35 +0200
Message-ID: <372C1342.A46DD544@sap-ag.de>


Hi,

I think You should use a SEQUENCE to solve Your problem. For a sequence named SEQ You have to change the insert statement to:

statement.executeUpdate ("INSERT INTO mytable VALUES (SEQ.NEXTVAL, myvalue1, myvalue2,...)");

and You have to use SEQ.CURRVAL instead of the 0 for all other occurances.

You can creat the SEQENCE with the following statement: CREATE SEQUENCE SEQ; The user who insert the rows needs the select privilege on the SEQUENCE or the SELECT ANY SEQUENCE privilege.

I hope that I can help You

Fredrik Öhrn wrote:

> Hello!
>
> I'm working on a java applet that adds records to an Oracle database.
>
> To add a new record I use the following construct:
> statement.executeUpdate ("INSERT INTO mytable VALUES (0, myvalue1, myvalue2,
> ...)");
>
> The catch is that the first 0 is a primary key column and the server
> automatically assigns a unique running number instead of the value I provide.
> How can I get hold of the server assigned primary key value? I need it to add
> records to other tables that has this key as a foreign key.
>
> Any input is appreciated.
>
> Regards,
> Fredrik
>
> --
>
> I don't see why there's a problem with computers thinking
> it's the year 1900. Computers weren't even invented in 1900.
>
> Fredrik Öhrn Chalmers University of Technology
> d96ohrn_at_ios.chalmers.se Sweden

--
Best Regards,

Ralph Ganszky

Received on Sun May 02 1999 - 03:56:35 CDT

Original text of this message

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