PLSQL :NEW and :OLD

前端 未结 13 1207
孤街浪徒
孤街浪徒 2020-12-24 06:30

Can anyone help me understand when to use :NEW and :OLD in PLSQL blocks, I\'m finding it very difficult to understand their usage.

13条回答
  •  清歌不尽
    2020-12-24 06:53

    :old and :new are pseudorecords referred to access row level data when using row level trigger.

    • :old - refers to Old Value
    • :new - refers to New value

    For Below operation, respective old and new values:

    1. INSERT- :old.value= NULL, :new value= post insert value
    2. DELETE- :old.value= Pre Delete value, :new value= null
    3. UPDATE- :old.value= Pre update value, :new value= Post Update value

    Eg:

    CREATE OR REPLACE TRIGGER get_dept
      BEFORE DELETE OR INSERT OR UPDATE ON employees
      FOR EACH ROW
    BEGIN
        DBMS_OUTPUT.PUT('Old Dept= ' || :OLD.dept|| ', ');
      DBMS_OUTPUT.PUT('New Dept= ' || :NEW.dept );
    END;
    

    Triggering Statement:

    UPDATE employees
    SET dept ='Accounts'
    WHERE empno IN (101 ,105);
    

提交回复
热议问题