无法理解":new"的工作


if (false = FALSE) then  
:NEW.last_modified := sysdate;
:new.ssn := null;

在行级触发器中,我们通常使用: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)

最新更新