触发器

create or replace trigger tri_comms
after insert on tbl_users_comment
for each row
declare
  v_id number;
  v_cls varchar2(1);
begin
  v_id := :new.data_id;
  v_cls := :new.comm_cls;
  if v_cls = '1' then
    update tbl_tech_achv set comms = comms + 1 where id = v_id;
  end if;
  if v_cls = '2' then
    update tbl_tech_demand set comms = comms + 1 where id = v_id;
  end if;
  if v_cls = '3' then
    update tbl_info_expert set comms = comms + 1 where id = v_id;
  end if;
end;


CREATE OR REPLACE TRIGGER "FYSCIENCE"."TRI_COMMS"
after insert on tbl_users_comment
for each row
declare
  v_id number;
  v_cls varchar2(1);
begin
  v_id := :new.data_id;
  v_cls := :new.comm_cls;
  if v_cls = '1' then
    update tbl_tech_achv set comms = comms + 1 where id = v_id;
  end if;
  if v_cls = '2' then
    update tbl_tech_demand set comms = comms + 1 where id = v_id;
  end if;
  if v_cls = '3' then
    update tbl_info_expert set comms = comms + 1 where id = v_id;
  end if;
end;

CREATE TRIGGER TRI_COLLS
after insert
on tbl_base_colls
for each row
declare
    v_id number;
    v_cls varchar2(1);
begin
    v_id := :new.data_id;
    v_cls := :new.colls_cls;
    if v_cls = '1' then
            update tbl_tech_achv set colls = colls + 1 where id = v_id;
    end if;
    if v_cls = '2' then
        update tbl_tech_demand set colls = colls + 1 where id = v_id;
        end if;
        if v_cls = '3' then
            update tbl_info_expert set colls = colls + 1 where id = v_id;
        end if;
        if v_cls = '4' then
            update tbl_users_member set colls = colls + 1 where id = v_id;
        end if;
    if inserting then
        
    end if;
    if deleting then
        if v_cls = '1' then
            update tbl_tech_achv set colls = colls - 1 where id = v_id;
        end if;
        if v_cls = '2' then
            update tbl_tech_demand set colls = colls - 1 where id = v_id;
        end if;
        if v_cls = '3' then
            update tbl_info_expert set colls = colls - 1 where id = v_id;
        end if;
        if v_cls = '4' then
            update tbl_users_member set colls = colls - 1 where id = v_id;
        end if;
    end if;
end;


最终版=============================================================================================================

create or replace trigger "TRI_COLLS"
before insert or delete on tbl_base_colls
for each row
declare
    v_id number;
    v_cls varchar2(1);
begin
    if inserting then
      v_id := :new.data_id;
      v_cls := :new.colls_cls;
      if v_cls = '1' then
          update tbl_tech_achv set colls = colls + 1 where id = v_id;
      end if;
      if v_cls = '2' then
          update tbl_tech_demand set colls = colls + 1 where id = v_id;
      end if;
      if v_cls = '3' then
          update tbl_info_expert set colls = colls + 1 where id = v_id;
      end if;
      if v_cls = '4' then
          update tbl_users_member set colls = colls + 1 where id = v_id;
      end if;
    end if;
    if deleting then
      v_id := :old.data_id;
      v_cls := :old.colls_cls;
      if v_cls = '1' then
          update tbl_tech_achv set colls = colls - 1 where id = v_id;
      end if;
      if v_cls = '2' then
          update tbl_tech_demand set colls = colls - 1 where id = v_id;
      end if;
      if v_cls = '3' then
          update tbl_info_expert set colls = colls - 1 where id = v_id;
      end if;
      if v_cls = '4' then
          update tbl_users_member set colls = colls - 1 where id = v_id;
      end if;
    end if;
end;

 

create or replace trigger "TRI_COMMS"
after update on tbl_users_comment
for each row
declare
  v_id number;
  v_cls varchar2(1);
  v_state varchar2(1);
  v_isdel varchar2(1);
begin
  v_id := :old.data_id;
  v_cls := :old.comm_cls;
  v_state := :new.comm_state;
  v_isdel := :new.is_del;
  if v_state = '0' then
    if v_cls = '1' then
      update tbl_tech_achv set comms = comms + 1 where id = v_id;
    end if;
    if v_cls = '2' then
      update tbl_tech_demand set comms = comms + 1 where id = v_id;
    end if;
    if v_cls = '3' then
      update tbl_info_expert set comms = comms + 1 where id = v_id;
    end if;
  end if;
  if v_isdel = '1' then
    if v_cls = '1' then
      update tbl_tech_achv set comms = comms - 1 where id = v_id;
    end if;
    if v_cls = '2' then
      update tbl_tech_demand set comms = comms - 1 where id = v_id;
    end if;
    if v_cls = '3' then
      update tbl_info_expert set comms = comms - 1 where id = v_id;
    end if;
  end if;
end;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值