Subject: Re: Generators for Primary Keys
Newsgroups: comp.databases.oracle.misc
References: <33AA8194.2F78@kwsoft.de>
Reply-To: akaplan@interaccess.com
Distribution: 

Uwe Grauer (grauer@kwsoft.de) wrote:
: Does Oracle support Generators (gen_id) to get unique
: Integers for Primary Keys?
: If not, how do People get unique Integers for Primary Keys?
: TIA,
: 	Uwe

Uwe,

Use a SEQUENCE to generate unique numbers for your primary keys. Oracle
handles sequences very well in regards to data consistency... when
transactions are rolled back, the sequence does not "roll back" to an
earlier value.

To fully explain sequences is beyond the scope of a simple post, but I
will show the basic commands below:

CREATE A SEQUENCE:
create sequence UWE_SEQUENCE start with 1 maxvalue 999999 increment by 1;

FIND THE CURRENT VALUE (without incrementing):
select UWE_SEQUENCE.CURRVAL from dual;

FIND THE NEXT VALUE (and increment):
select UWE_SEQUENCE.NEXTVAL from dual;

-Ari Kaplan
Independent Oracle DBA Consultant

<-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><->
<-> For 70+ technical tips, visit my Web Page:                    <->
<->                                                               <->
<->              www.arikaplan.com                                <->
<->                                                               <->
<->             email: akaplan@interaccess.com                    <->
<-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><->

Back to Ari Kaplan's Home Page m">Back to Ari Kaplan's Home Page