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 -> how to achieve autoincremented PKs (as datatype SERIAL does)

how to achieve autoincremented PKs (as datatype SERIAL does)

From: Frank Ratzlow <frank_ratzlow_at_hotmail.com>
Date: 27 Feb 2003 03:57:00 -0800
Message-ID: <5ef29569.0302270357.1adad160@posting.google.com>


Hallo folks,

is it possible to put the handling of autogenerating PK to Oracle? I think to remember from Informix the datatype SERIAL that makes it quite easy as I don't have to determine a new value for the key. I just would like to insert a row without having to know or (calculate) the value of the new record. For a short time I thought of:



INSERT INTO customer (customerid, firstname, lastname) VALUES ((SELECT MAX(customerid) FROM customer) + 1, 'Sven', 'Grundmann');

but this cannot be a serious solution since it would run into trouble with concurrent inserts.
Could anyone give me a hint how to implement something I only have to do something like

INSERT INTO customer VALUES ('Sven','Grundmann');

Finally, to top all this I want to execute this statment from within Java Code via JDBC. Is there any supported way to precalc the pk?

TIA Frank
frank_ratzlow_at_nojunk.hotmail.com Received on Thu Feb 27 2003 - 05:57:00 CST

Original text of this message

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