触发器

create or replace trigger tr_ckyjqbxx_bjxxjl
before insert or update of SJQSZT on dtjf.t_zt_zdry_cklkyjqbxx for each row
--常控临控预警触发报警信息
declare

begin
       if inserting then
          --dbms_output.put_line(:old.yjlx);
           --有新的常控预警信息,将触发生产报警记录信息,并且预警接收地类型 必须是活动的 
           --并且本地关注人员,无需报警 及 yjjb ='9' 为本地关注人员
           if :new.yjlx='1' and :new.yjjsdlx='1' and :new.yjjb!='9' then
              --当有新的预警信息到来,将触发一条报警信息
              insert into dtjf.t_bjq_bjxxjl(
                    bjbh,ldxxbh,yjxxbh,bjsj,bjlx,bjlxmc,bjxx,bjnr,bjcldwdm,sjzt
              )values(
                    to_char(sysdate,'yyyymmddhh24miss')||lpad(seq_bjbh.nextval,4,'0'),
                    :new.ldxxbh,:new.yjxxbh,to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),:new.yjjb,
                    decode(:new.yjjb,'1','红色预警','2','橙色预警','4','黄色预警','5','蓝色预警'),
                    '常控预警待处理',:new.bz ||' '||:new.hdxgxx,:new.DQCLJGDM, '0'
             );
           end if;
            --临控预警提示报警,本地比对产生预警,将提示报警
            -- if :new.yjlx='2' then
            --   insert into t_bjq_bjxxjl(
            --        bjbh,ldxxbh,yjxxbh,bjsj,bjlx,bjlxmc,bjxx,bjnr,bjcldwdm,sjzt
            --  )values(
            --        to_char(sysdate,'yyyymmddhh24miss')||lpad(seq_bjbh.nextval,4,'0'),
            --        :new.ldxxbh,:new.yjxxbh,to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),:new.yjjb,
            --        decode(:new.yjjb,'1','一级预警','2','二级预警','3','三级预警'),
            --        '临控预警待处理',:new.hdxgxx,:new.DQCLJGDM, '0'
            -- );
            -- end if;
       end if;
       
       --数据更新操作
       if updating then
          if :old.yjlx='1' then
            --更新前的数据状态和更新后的数据状态要求不一致,才能产生预警
            if :new.SJQSZT<>:old.sjqszt then
             --当常控预警转发,或要求反馈的时候将触犯报警, 并且预警接收地类型必须是活动的
               if (:new.SJQSZT ='6' or :new.SJQSZT='1' or :new.SJQSZT='3') AND :OLD.YJJSDLX='1' then
                   insert into dtjf.t_bjq_bjxxjl(
                      bjbh,ldxxbh,yjxxbh,bjsj,bjlx,bjlxmc,bjxx,bjnr,bjcldwdm,sjzt
                   )values(
                      to_char(sysdate,'yyyymmddhh24miss')||lpad(seq_bjbh.nextval,4,'0'),
                      :old.ldxxbh,:old.yjxxbh,to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),:old.yjjb,
                      decode(:old.yjjb,'1','红色预警','2','橙色预警','4','黄色预警','5','蓝色预警'),
                      '常控预警待处理',:old.bz ||'' || :old.hdxgxx,:new.DQCLJGDM,'0'
                  );
              end if;
           end if; 
         end if;
       end if;
end;


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值