Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Newbie, Autoincrement ??
> I am very new on ORACLE, How do I have a field that is autoincrement ??
First you create a sequence (an object that in general just keeps a number and increases it on demand), e.g.
CREATE SEQUENCE SEQ_TEST MINVALUE 1 MAXVALUE 99999999999 INCREMENT BY 1 START WITH 0 CACHE 20 NOORDER CYCLE; Second, you create a trigger that "catches" all inserts into a table. A trigger fitting this sequence would look like this...
CREATE OR REPLACE TRIGGER TRG_PK_TEST
BEFORE INSERT ON TEST
FOR EACH ROW
BEGIN
SELECT
SEQ_TEST.NEXTVAL into :NEW.TEST_ID
FROM
DUAL;
END;
Regards,
Thomas Bierhance Received on Tue Aug 03 1999 - 16:01:57 CDT
![]() |
![]() |