1

我有一个关于综合触发器的问题。如果有任何事件与过滤器匹配,我使用此触发器发送电子邮件。

这是过滤器:

begin

for each row critical in alerts.status where critical.Severity = 5 and 
critical.Grade <= 6 and critical.LastOccurrence <= ( getdate() - (60*30) )          
begin
execute send_email( critical.Node, critical.Severity, 'test2@npp.local','Netcool Email',  critical.Summary, 'WINITMSVR631');
update alerts.status via critical.Identifier set Grade=7;
end;

end

我成功发送了一封带有上述触发器的电子邮件,

我想在触发器中添加几行,它看起来像这样:

begin

for each row critical in alerts.status where critical.Severity = 5 and 
critical.Grade <= 6
if critical.Situation = 'blabla1'       
{begin
execute send_email( critical.Node, critical.Severity, 'test2@npp.local','Netcool Email',  critical.Summary, 'WINITMSVR631');
update alerts.status via critical.Identifier set Grade=7;
end;}
if critical.Situation = 'blabla2'       
{begin
execute send_email2( critical.Node, critical.Severity, 'test2@npp.local',        'Netcool Email',  critical.Summary, 'WINITMSVR631');
update alerts.status via critical.Identifier set Grade=7;
end;}

end

但我总是对此有一些错误。老实说,我几乎不知道 sql 编程。

任何建议

谢谢您的帮助

4

1 回答 1

0

第一件事-我不确定您是否可以在触发代码中使用“{”和“}”。语法更像if Node = 'SomeNode' then update alerts.status set Grade = 8; end if;- 所以它的if ... then ...; 万一;

我已经修复了你的代码,它通过了 SQL 验证:

begin

for each row critical in alerts.status where critical.Severity = 5 and 
critical.Grade <= 6
begin
if (critical.Node = 'blabla1') then      
execute send_email( critical.Node, critical.Severity, 'test2@npp.local','Netcool Email',  critical.Summary, 'WINITMSVR631');
update alerts.status via critical.Identifier set Grade=7;
end if;
if (critical.Node = 'blabla2') then
execute send_email( critical.Node, critical.Severity, 'test2@npp.local','Netcool Email',  critical.Summary, 'WINITMSVR631');      
update alerts.status via critical.Identifier set Grade=7;
end if;
end;
end
于 2016-11-02T14:13:08.827 回答