Oracle Auto-Increment Trigger Guide
To achieve the auto-increment functionality, you can use a sequence in a trigger to achieve the auto-increment effect. Here is an example code.
CREATE SEQUENCE my_seq START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER my_trigger
BEFORE INSERT ON my_table
FOR EACH ROW
BEGIN
SELECT my_seq.NEXTVAL INTO :new.id FROM dual;
END;
/
In the code above, a sequence named my_seq is first created, followed by a trigger named my_trigger. This trigger automatically assigns the next value from the my_seq sequence to the id column when inserting a new record into my_table, achieving auto-increment functionality.