Oracle 更新前触发器未为空值创建历史记录
我的更新前触发器不会创建将null值更改为任何其他值的历史记录。它正在创建更改任何其他值的历史记录。 我的主要逻辑如下:Oracle 更新前触发器未为空值创建历史记录,oracle,Oracle,我的更新前触发器不会创建将null值更改为任何其他值的历史记录。它正在创建更改任何其他值的历史记录。 我的主要逻辑如下: if nvl(:old.place,null) <> nvl(:new.place,null) then insert into table (place) values(:old.place) end if; 如果nvl(:old.place,null)nvl(:new.place,null),则 插入表格(位置) 值(:old.place)
if nvl(:old.place,null) <> nvl(:new.place,null) then
insert into table (place)
values(:old.place)
end if;
如果nvl(:old.place,null)nvl(:new.place,null),则
插入表格(位置)
值(:old.place)
如果结束;
用于替换值以代替null。您正在将null替换为。。。null,这是没有意义的。然后尝试使用(in)相等运算符比较两个null值,由于null既不等于也不等于任何值(包括其本身),因此结果未知,如果旧值或新值为null,则条件始终为false
您可以使用您知道永远不会实际退出的固定虚拟值:
if nvl(:old.place,'**fake**') <> nvl(:new.place,'**fake**') then
您的问题是比较
'any value'null
总是错误的,就像这个:'any value'=null
。您应该使用IS NULL
进行空比较。
if (:old.place is null and :new.place is not null)
or (:old.place is not null and :new.place is null)
or (:old.place != :new.place) then