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: Sequence/Identity

Re: Sequence/Identity

From: Matthias Lippmann <news_at_lippmannsoft.de>
Date: Thu, 15 Jul 2004 13:09:15 +0200
Message-ID: <cd5oj3$nb2$1@beech.fernuni-hagen.de>


"Ernest Morariu" asked ..

> It is possible in Oracle 8i to define a column(called ID) in a table as
been
> value-autogenerated or Identity(as in SqlServer)?
> Is there any alternative to the sequences for generating the new IDs for
my
> tables ?

Use a sequence in combination with before-insert trigger for your table to fill your ID column.

Example:

CREATE OR REPLACE TRIGGER mytable_autovalue BEFORE INSERT ON mytable
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
BEGIN
 SELECT mysequence.NEXTVAL INTO :NEW.id FROM DUAL; EXCEPTION
 WHEN OTHERS THEN
  NULL;
END; Best Regards,

Matthias Lippmann

-- 
www.lippmannsoft.de
Received on Thu Jul 15 2004 - 06:09:15 CDT

Original text of this message

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