Skip to main content
← PL/SQL Topics

Triggers

Explain :NEW and :OLD in row-level triggers

:NEW and :OLD Pseudorecords

ExplanationOracle Fusion / EBS · Technical · PL/SQLHigh confidenceGenerated

:OLD holds the row's values before the change, :NEW holds them after; which are populated depends on the DML.

How it works

In a FOR EACH ROW trigger, :OLD and :NEW are pseudorecords shaped like the table. On INSERT, :OLD is NULL and :NEW is the incoming row. On UPDATE both are set. On DELETE, :NEW is NULL and :OLD is the row being removed. In a BEFORE row trigger you may assign to :NEW.column to change what gets written (e.g. default or normalise a value); in AFTER triggers :NEW is read-only. In the WHEN clause and SQL statements, drop the colon (NEW.salary).

How it works
CREATE OR REPLACE TRIGGER trg_emp_normalise
  BEFORE INSERT OR UPDATE ON employees
  FOR EACH ROW
BEGIN
  :NEW.email := UPPER(TRIM(:NEW.email));
  IF INSERTING THEN
    :NEW.created_on := SYSTIMESTAMP;
  END IF;
  :NEW.updated_on := SYSTIMESTAMP;
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