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;
關於一個觸發器的實例
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.