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: Generators for Primary Keys

Re: Generators for Primary Keys

From: Ari Kaplan <akaplan_at_interaccess.com>
Date: 1997/06/20
Message-ID: <5oe539$9gg@nntp.interaccess.com>#1/1

Uwe Grauer (grauer_at_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:                    <->
<->                                                               <->
<->              http://homepage.interaccess.com/~akaplan         <->
<->                                                               <->
<->             email: akaplan_at_interaccess.com                    <->

<-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><->
Received on Fri Jun 20 1997 - 00:00:00 CDT

Original text of this message

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