oracle简单触发器

来源:互联网 发布:淘宝的特点和定位 编辑:程序博客网 时间:2024/06/17 04:46
触发器写法:create or replace trigger testTrigger  before insert or update or delete  on t_yunwei_group   for each rowdeclare  -- local variables herebegin  if inserting then    insert into t_yunwei_stalocation t1 (t1.c_groupid,t1.c_groupName,t1.c_filecontent) values (:NEW.c_Groupid,:NEW.c_groupname,' ');  end if;    if updating then    update t_yunwei_stalocation t1 set t1.c_groupname=:NEW.c_groupname where t1.c_groupid=:NEW.c_Groupid;  end if;    if deleting then    delete from t_yunwei_stalocation t1 where t1.c_groupid=:OLD.c_Groupid;  end if;end testTrigger;注: :old  与:new 的区别: 顾名思义,new是新插入的数据,old是原来的数据insert只会有new,代表着要插入的新记录delete只会有old,代表着要删除的记录update由于执行的是先删除旧的记录,再插入新的记录,因此new和old都会有,且含义与上面的相同注:update触发器,可根据具体需求选择记录旧记录还是新记录。

0 0
原创粉丝点击