Skip to main content
← PL/SQL Topics

Triggers

Explain trigger ordering with FOLLOWS and PRECEDES

Trigger Ordering with FOLLOWS and PRECEDES

ExplanationOracle Fusion / EBS · Technical · PL/SQLHigh confidenceGenerated

When several triggers of the same timing point exist on one table, FOLLOWS / PRECEDES fixes their relative firing order.

How it works

Historically the firing order of multiple same-event triggers was undefined. Since 11g a trigger can declare FOLLOWS other_trigger (fire after it) or PRECEDES other_trigger, letting you make one BEFORE ROW trigger depend on another's changes to :NEW. Only a partial order is needed — triggers you do not name stay unordered relative to yours. Compound triggers avoid the issue by putting all sections in one object.

How it works
CREATE OR REPLACE TRIGGER trg_set_defaults
  BEFORE INSERT ON orders FOR EACH ROW
BEGIN
  :NEW.status := NVL(:NEW.status, 'NEW');
END;
/
CREATE OR REPLACE TRIGGER trg_validate_after_defaults
  BEFORE INSERT ON orders FOR EACH ROW
  FOLLOWS trg_set_defaults           -- guaranteed to see the default applied
BEGIN
  IF :NEW.status NOT IN ('NEW','HOLD') THEN
    RAISE_APPLICATION_ERROR(-20050, 'bad status');
  END IF;
END;
/

Related questions

GroundingGenerated

Model-generated, grounded against the curated knowledge layer. Check specifics against your instance.

Have a follow-up, or a different question?

Continue in Ask Oracle AI