触发器

来源:互联网 发布:网络跑路了是什么意思 编辑:程序博客网 时间:2024/05/21 00:53
create or replace trigger tr_ckyjqbxx_bjxxjlbefore insert or update of SJQSZT on dtjf.t_zt_zdry_cklkyjqbxx for each row--常控临控预警触发报警信息declarebegin       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;