判斷oracle單條表記錄更新時更新的是哪幾個字段
首先使用觸發器判斷執行的是否是更新語句
create or replace trigger jc_customer_upd_tr before insert or update on jc_customer for each row --行級觸發 declare v_operation varchar2(500);--操作內容 begin --如果信息變更,則將變更的字段提取出來,拼接並插入日志表中的一個字段 if updating then
end if; end jc_customer_upd_tr;
判斷更改的哪些字段,方法一是插入之前進行新舊值的比對
if :OLD.Name!=:NEW.Name then v_operation:=v_operation||'舊1:'||:OLD.Name||'新1:'||:NEW.Name||';'; end if;
另外一種方法是使用updating('XX')的方法來判斷更新語句是否含有該字段的更新
if updating('Name') then v_operation:=v_operation||'舊2:'||:OLD.Name||'新2:'||:NEW.Name||';'; end if;