oracle简单触发器

触发器写法:
create or replace trigger testTrigger
  before insert or update or delete
  on t_yunwei_group 
  for each row
declare
  -- local variables here
begin
  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触发器,可根据具体需求选择记录旧记录还是新记录。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值