Can anyone help me understand when to use :NEW
and :OLD
in PLSQL blocks, I\'m finding it very difficult to understand their usage.
It's very simple
If Insert :old = NULL and :New = New Inserted Value
If Update :Old = Value already in the table :New = Updated Value in the Table
If Delete :Old = Value before deletion :New = NULL
IN other Words
For an INSERT trigger, OLD contains no values, and NEW contains the new values.
For an UPDATE trigger, OLD contains the old values, and NEW contains the new values.
For a DELETE trigger, OLD contains the old values, and NEW contains no values.
Example:
CREATE OR REPLACE TRIGGER update_name_view_trigger
INSTEAD OF UPDATE ON emp_locations
BEGIN
UPDATE employees SET
first_name = substr( :NEW.name, instr( :new.name, ',' )+2),
last_name = substr( :NEW.name, 1, instr( :new.name, ',')-1)
WHERE employee_id = :OLD.employee_id;
END;