Can anyone help me understand when to use :NEW
and :OLD
in PLSQL blocks, I\'m finding it very difficult to understand their usage.
:old and :new are pseudo records referred to access row level data when using row level trigger.
•:old - refers to Old Value •:new - refers to New value
for example:
CREATE OR REPLACE TRIGGER mytrig BEFORE
INSERT OR
UPDATE
ON mytab FOR EACH ROW
BEGIN
IF INSERTING THEN
SELECT trunc(sysdate), trunc(sysdate) INTO :new.created, :NEW.last_updated FROM DUAL;
END IF; --INSERTING
IF UPDATING THEN
SELECT trunc(sysdate) INTO :NEW.last_updated FROM DUAL;
END IF; --UPDATING
END;
Hope this explains the concept of old and new.