Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: How do I retrive newly added records?
In article <372af889.2552521_at_news.chalmers.se>,
Fredrik Öhrn <d96ohrn_at_ios.chalmers.se> wrote:
>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.
If you use DBMS_SQL to insert your rows, you can use the DBMS_SQL.Last_Row_Id function to retrieve the rowid of the record just inserted, and then select that row and see your new key value.
It would probably be best to create a package procedure on the server that your process calls, sending it the column values to insert, and returning the new key value. The procedure could make all the necessary DBMS_SQL calls, and do the subsequent select to look up the new primary key value using the rowid.
Steve Cosner
http://members.aol.com/stevec5088
Received on Sat May 01 1999 - 10:57:15 CDT
![]() |
![]() |