oracle trigger触发器

– 记录TRIGGER表

create or replace table BY_TRIGGER_LOG
(
  trig_name   varchar2(255),
  trig_time   varchar2(255),
  trig_table  varchar2(255),
  trig_column varchar2(255),
  trig_value  varchar2(255),
  trig_id varchar2(255)
)
;
--如果更新BY_GOODS的STATE字段,则插入一条记录
create or replace trigger TRIGGER_BY_GOODS
 before update 
   on BY_GOODS
   for each row 
begin
  if updating ('STATE')
    then 
      insert into BY_TRIGGER_LOG (trig_name,trig_time,trig_table,trig_column,trig_value,trig_id) 
      values ('TRIGGER_BY_GOODS',to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'BY_GOODS','STATE',:new.STATE,:new.FNUMBER);
  end if;
end;
--如果删除则备份
if deleting then
--flastupdatetime为删除时间
insert into t_sd_saleorder_delbak
  (fid, fcreatorid, fcreatetime, fmodifierid, fmodificationtime, flastupdateuserid, flastupdatetime, fcontrolunitid, fnumber, fbizdate, fhandlerid, fdescription, fhaseffected, fauditorid, fsourcebillid, fsourcefunction, faudittime, fbasestatus, fbiztypeid, fsourcebilltypeid, fbilltypeid, xxxxxxxx)
values
  (:OLD.fid, :OLD.fcreatorid, :OLD.fcreatetime, :OLD.fmodifierid, :OLD.fmodificationtime, :OLD.flastupdateuserid, sysdate, :OLD.fcontrolunitid, :OLD.fnumber, :OLD.fbizdate, :OLD.fhandlerid, :OLD.fdescription, :OLD.fhaseffected, :OLD.fauditorid, :OLD.fsourcebillid, :OLD.fsourcefunction, :OLD.faudittime, :OLD.fbasestatus, :OLD.fbiztypeid, xxxxxxxxxxxxx);
--如果该值则更新其他标志
  if :new.FORGUNIT =  'uaPiuJuNQiSGRMh73zHEdMznrtQ=' and :new.FISPARTICIPATEREDUCT = 0  then
     :NEW.FISPARTICIPATEREDUCT :=  1;

这是更新之前存储的情况,也有更新后存储的,例如,

你可能感兴趣的:(数据库)