Creating Oracle Sequence Trigger
Try this:
CREATE OR REPLACE TRIGGER TRIGGER1
BEFORE INSERT ON ACCOUNTS
FOR EACH ROW
WHEN (new.ID IS NULL)
BEGIN
:new.ID := ACCOUNTS_SEQ.NEXTVAL;
END;
/
Your sequence should look like this:
CREATE SEQUENCE ACCOUNTS_SEQ
START WITH 1
INCREMENT BY 1;
CREATE OR REPLACE TRIGGER TRIGGER1
BEFORE INSERT ON ACCOUNTS
FOR EACH ROW
BEGIN
IF :new.ID IS NULL THEN
SELECT ACCOUNTS_SEQ.NEXTVAL
INTO :new.ID
FROM dual;
END IF;
END;