Definition:
In Oracle PL/SQL, NEW is an identifier used in row level DML triggers. It signifies the new pseudo record and refers the column used in the DML statement. Columns of the new pseudo record can be referenced by prefixing each column with :NEW identifier.
Example Syntax:
[:] [OLD | NEW] [.] [COLUMN NAME]
Example Usage:
In this example a row level trigger named T_UPD_EMP is created. It fires before the EMPLOYEE table is updated and displays the Employee name and his or her old and new hire dates.
SQL>
CREATE OR REPLACE TRIGGER T_UPD_EMP
BEFORE UPDATE ON EMPLOYEE
FOR EACH ROW
BEGIN
DBMS_OUTPUT.PUT_LINE('Update Employee '||:OLD.ENAME);
DBMS_OUTPUT.PUT_LINE('Old Hiredate = '||:OLD.HIREDATE||' New Hiredate = '||:NEW.HIREDATE);
END;
Trigger created.
SQL> UPDATE EMPLOYEE
SET HIREDATE=HIREDATE+10;
Update Employee MICK
Old Hiredate = 31-JUL-10 New Hiredte = 10-AUG-10
Update Employee CARSON
Old Hiredate = 21-JUL-10 New Hiredate = 31-JUL-10
Update Employee MILLER
Old Hiredate = 11-JUL-10 New Hiredate = 21-JUL-10
Update Employee ROGERS
Old Hiredate = 01-JUL-10 New Hiredate = 11-JUL-10
4 rows updated.
Related Links:
Related Code Snippets: