Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#78 ORACLE trigger code generation

closed
None
5
2013-10-11
2012-02-24
Anonymous
No

When writting triggers for sequences in ORACLE is a good practice to assign the sequence id only if it was not assigned before. This is because, in some case, the sequence must be generated from another process (e.g. for key propagation).

The trigger code must finish with slash (/) in order to be runned as script.

This is a sample:

CREATE OR REPLACE TRIGGER TRI_DEPARTAMENTS_DEPART_ID BEFORE INSERT ON DEPARTAMENTS
FOR EACH ROW
BEGIN
IF :NEW.DEPART_ID IS NULL THEN
SELECT SEQ_DEPARTAMENTS_DEPART_ID.NEXTVAL
INTO :NEW.DEPART_ID
FROM DUAL;
END IF;
END;
/

Discussion

    • status: open --> closed
    • assigned_to: Hiroyuki Nakajima
    • Group: --> Next Release (example)