CREATE OR REPLACE TRIGGER MAILMODIFY
AFTER INSERT
ON DYNAMIC_ALARM
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
MAIL login.notify_sms%TYPE;
RNAME login.real_name%TYPE;
MES notifytempinfo.message%TYPE;
DALARMID dynamic_alarm.dynamic_alarm_uid%Type;
s Constant Char(1) := ','; -- 逗号分隔条件
c Int := 1; --查找第几个逗号
f Int := 1; -- 从哪开始截取
e Int := 1; -- 记录接却后的位置
pos Int := 0; --共截取几位
CURSOR cur_operation
is
SELECT d.real_name,d.notify_email
from ne e,alarm_def a,r_ne_position b,r_login_position c,login d
where a.ne_uid=:new.ne_uid
and a.alarm_kpi_code=:new.kpi_code
and b.ne_uid=getTopNe(:new.ne_uid)
and b.position_id=c.position_id
and c.login_name=d.login_name
and :new.alarm_level >=d.EMAIL_LEVEL
and d.NOTIFY_EMAIL is not null
and decode(d.CUSTOMIZE_NOTIFY,1,getNotifyTime(d.EMAIL_PERIOD),getZhiBanStatus(d.login_name))>0
and e.ne_uid=:new.ne_uid
and d.login_status=0
and substr(:new.alarm_start_time,9,5)>='01 07';
begin
----------------------------------
dbms_output.put_line('----sssss');
SELECT
DISTINCT e.display_name||'在'||:new.alarm_start_time||decode(:new.alarm_level,1,' 轻微',2,' 重要',' 严重')||'告警:'||a.alarm_def_name||' 值:'||:new.alarm_trigger_value into MES
from v_my_ne e,alarm_def a,r_ne_position b,r_login_position c,login d
where e.login_name=d.login_name
and a.ne_uid=:new.ne_uid
and a.alarm_kpi_code=:new.kpi_code
and b.ne_uid=getTopNe(:new.ne_uid)
and b.position_id=c.position_id
and c.login_name=d.login_name
and :new.alarm_level >=d.EMAIL_LEVEL
and d.NOTIFY_EMAIL is not null
and decode(d.CUSTOMIZE_NOTIFY,1,getNotifyTime(d.EMAIL_PERIOD),getZhiBanStatus(d.login_name))>0
and e.ne_uid=:new.ne_uid
and d.login_status=0
and substr(:new.alarm_start_time,9,5)>='01 07';
dbms_output.put_line('----'||MES);
Exception
When no_data_found Then
MES := '';
/*SELECT dynamic_alarm_uid into DALARMID
from dynamic_alarm
where dynamic_alarm_uid=:new.dynamic_alarm_uid;*/
--打开游标
open cur_operation;
--取出数据
fetch cur_operation into RNAME,MAIL;
--循环
while cur_operation%found
Loop
c := 1; --查找第几个逗号
f := 1; -- 从哪开始截取
e := 1; -- 记录接却后的位置
pos := 0; --共截取几位
Loop
e := instr(MAIL, s, 1, c) ;
pos := e + 1 - f;
If e = 0 Then
insert into mail_temp(mail_uid, mail,
title, content, kpi_code, ne_uid,
dynamic_alarm_uid, real_name,
alarm_level, status)
values (
seq_mail_temp.nextval,
substr(MAIL, f, length(MAIL)),
'APM 监控告警',
MES,
:new.kpi_code,
:new.ne_uid,
:new.dynamic_alarm_uid,
RNAME,
:new.alarm_level,
1
);
Exit;
Else
insert into mail_temp(mail_uid, mail,
title, content, kpi_code, ne_uid,
dynamic_alarm_uid, real_name,
alarm_level, status)
values (
seq_mail_temp.nextval,
substr(MAIL, f, length(MAIL)),
'APM 监控告警',
MES,
:new.kpi_code,
:new.ne_uid,
:new.dynamic_alarm_uid,
RNAME,
:new.alarm_level,
1
);
End If;
f := e + 1;
c := c + 1;
End Loop;
--Create Mail Info End
fetch cur_operation into RNAME,MAIL;
end loop;
--关闭游标
close cur_operation;
------------------------------------
end;
关于一个触发器的实例
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.