Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Sequence/Identity
"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.deReceived on Thu Jul 15 2004 - 06:09:15 CDT
![]() |
![]() |