快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

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://6mz.cn/article/ipdgde.html

其他资讯