Oracle创建触发器
create or replace trigger DATA_SYNC_@TABLE@ before insert or update or delete on @TABLE@ REFERENCING OLD AS old_emp NEW AS new_emp for each row begin --通过应用程序修改时,F_SYNC_UPDATE=null或F_SYNC_UPDATE=0,此时不需要更新F_SYNC_DATE 时间戳,也不需要记录删除记录 if (:new_emp.F_SYNC_UPDATE is null) or (:new_emp.F_SYNC_UPDATE = 0) then --插入和更新操作,更新时间戳F_SYNC_DATE=systimestamp和F_SYNC_UPDATE=null if INSERTING or UPDATING then select systimestamp, null into :new_emp.F_SYNC_DATE, :new_emp.F_SYNC_UPDATE from dual; end if; if INSERTING then --把新增加的记录插入到操作记录表 insert into DATA_SYNC_B_OPERATOR (t_name, o_type, o_date, VKEYS) values ('@TABLE@', 1, systimestamp, @INSERTVAL@); end if; if DELETING then --把删除记录的主键添加到操作记录表 insert into DATA_SYNC_B_OPERATOR (t_name, o_type, o_date, VKEYS) values ('@TABLE@', 3, systimestamp, @UPDATEVAL@); end if; end if; end DATA_SYNC_@TABLE@;
当前文章:Oracle创建触发器
文章地址:http://scyanting.com/article/ipdgde.html