2015-04-29 44 views
0

我更新前的觸發器未創建任何將空值更改爲任何其他值的歷史記錄。它正在創造改變任何其他價值觀的歷史。 我的主要邏輯是這樣的:在更新觸發器未創建空值歷史記錄之前

if nvl(:old.place,null) <> nvl(:new.place,null) then 
    insert into table (place) 
    values(:old.place) 
end if; 
+0

你的問題是, 'any value'<> null'的比較總是爲false,就像這樣:''any value'= null'。你應該使用'IS NULL'進行空比較。 – mustaccio

回答

0

The NVL() function使用代替空的替換值。你用null替換null,這是毫無意義的。然後你試圖比較兩個null值與(in)等號運算符,並且由於null既不等於也不等於或不等於包括它自身在內的任何值,所以結果是未知的,並且如果舊的或新的值爲空。

你可以使用你知道一個固定的虛值永遠不會真正退出:

if nvl(:old.place,'**fake**') <> nvl(:new.place,'**fake**') then 

但爲清楚起見我一般喜歡爲空明確測試:

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 
+0

它現在正在工作。謝謝 – user4826005

相關問題