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

Home -> Community -> Usenet -> c.d.o.tools -> Re: Autoincrement in Oracle

Re: Autoincrement in Oracle

From: Dirk P.C. Wendt <dpcw_at_gmx.de>
Date: 2000/06/12
Message-ID: <8i3dh0$454vn$2@fu-berlin.de>#1/1

Hello,

Florian Leibenzeder <flo_at_linx.net> schrieb:
> I am new to oracle and this is probably a faq question so if it is
> could somebody just post a link to the faq.
> Otherwise: Is there a way in Oracle8i to have a column which
> autoincrements whenever you add a new row. (Does it reindex when you
> remove something?)
> I just can't imagine that you have to check for the max(id) and
> increment that before adding a new row :-)

with Oracle 8.0.5 I am using the following. Think it's the same mechanism on 8i.

CREATE SEQUENCE xyz_ID_SEQ
increment by 1
start with 1
maxvalue 9999999
minvalue 0
cycle
nocache
noorder;

CREATE OR REPLACE TRIGGER xyz_ID BEFORE INSERT ON xyz FOR EACH ROW
begin
SELECT xyz_ID_SEQ.NEXTVAL INTO :New.xyz_ID FROM DUAL; END; Ciao, Dirk. Received on Mon Jun 12 2000 - 00:00:00 CDT

Original text of this message

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