web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

Oracle Auto Increment ID

Andre Margono Profile Picture Andre Margono 2,602

Oracle does not support the auto increment automatically. We need to create sequence and trigger before.

Sequence creation:

CREATE SEQUENCE sequence_name
MINVALUE value
MAXVALUE value
START WITH value
INCREMENT BY value
CACHE value;

example:

CREATE SEQUENCE book_sequence
MINVALUE 1
MAXVALUE 999999999999999999999999999
START WITH 1
INCREMENT BY 1
CACHE 20;

Trigger Creation:

CREATE OR REPLACE TRIGGER <trigger name> BEFORE INSERT ON <table name> REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT <sequence name>.nextval INTO :NEW.<id from table> FROM dual; END;

example:

CREATE OR REPLACE TRIGGER "BOOK_TRIGGER" BEFORE INSERT ON book REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT book_sequence.nextval INTO :NEW.BOOKID FROM dual; END;

That’s all hopefully it’s helpful..


This was originally posted here.

Comments

*This post is locked for comments