我有一个关于综合触发器的问题。如果有任何事件与过滤器匹配,我使用此触发器发送电子邮件。
这是过滤器:
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编程。
任何建议
谢谢你的帮助
答案 0 :(得分:0)
首先 - 我不确定你能否使用&#34; {&#34;和&#34;}&#34;在触发器代码中。
语法更像if Node = 'SomeNode' then update alerts.status set Grade = 8; end if;
- 所以如果 ... 那么 ...; 结束if;
我修复了你的代码并通过了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