首页 > 解决方案 > 无法理解 ':new' 的工作原理

问题描述

if (false = FALSE) then  

    :NEW.last_modified := sysdate;
:new.ssn := null;

标签: oracleamazon-web-servicesplsqldata-migration

解决方案


我们通常使用:OLD引用旧值和:NEW引用行级触发器中的新值。

的值:OLD:NEW可以在数据操作语言语句中变得不同。

向表中插入数据时

 :OLD = NULL (since no old record)  
 :NEW = Newly inserted value

更新表中的数据时

 :OLD = Value exists in the table before the UPDATE statement executes 
 :NEW = Newly received value to replace the existing value of the record

从表中删除数据时

 :OLD = Value exists in the table before the DELETE statement executes 
 :NEW = NULL

例如,假设您要以 Alex 的身份将新记录插入到Employee

 :OLD = NULL (since no old record)  
 :NEW = Alex

现在您要将值Alex更新为John

 :OLD = Alex
 :NEW = John

当您删除此记录时,

 :OLD = John
 :NEW = NULL (since the record has been deleted)

推荐阅读