PLSQL :NEW and :OLD

前端 未结 13 1052
孤街浪徒
孤街浪徒 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 07:18

    :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.

    0 讨论(0)
提交回复
热议问题