Creating a trigger for a sequence that works for auto-increment of PK

after creating a sequence like ‘SEQUENCE_NAME_SEQ’ that will increase value from 1 and by 1. then this code will be executed.


CREATE OR REPLACE TRIGGER "DATABASE_NAME"."BI_TRIGGER_NAME" 
  before insert on "TABLE_NAME"               
  for each row  
begin   
    select "SEQUENCE_NAME_SEQ".nextval into :NEW.PRIMARY_KEY_NAME from dual; 
end; 
/
ALTER TRIGGER "DATABASE_NAME"."BI_TRIGGER_NAME" ENABLE;

This entry was posted in Uncategorized.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s