Oracle触发器中select into 报错no_data_found异常处理

红色部分为对查询不到数据异常的处理

create or replace trigger TIG_MONITOR_ALARM

after insert on t_monitor_real_minute
for each row
declare
-- 标准值
standvalue number;
--报警实况表id
liveid number;
begin
--
--触发器功能:监测实况数据表,对比监测数据是否超标,超标数据则记录入超标报警表中
--
standvalue:=-1;
liveid:=-1;
select nvl(t.bzz,-1) into standvalue from t_monitor_factor t where t.jcdbm=:new.STATION_ID and t.jcxmbm=:new.INFECTANT_ID;

--如果录入检测项目数据大于标准值,则入库报警信息表中
if standvalue>-1 then
if :new.M_VALUE>standvalue then
--将数据录入报警历史数据中
insert into t_alarm_history(id,jcdbm,jcxmbm,mvalue,mtime)
values(SEQ_ALARM_HISTORY.NEXTVAL,:new.STATION_ID,:new.INFECTANT_ID,:new.M_VALUE,:new.M_TIME);

--异常判断,如果查询不到数据
begin
select r.id into liveid from t_alarm_real r where r.jcdbm=:new.STATION_ID and r.jcxmbm=:new.INFECTANT_ID;
--查询不到数据
EXCEPTION
WHEN no_data_found THEN

--不存在则录入新的报警实况
insert into t_alarm_history(id,jcdbm,jcxmbm,mvalue,mtime)
values(SEQ_ALARM_REAL.NEXTVAL,:new.STATION_ID,:new.INFECTANT_ID,:new.M_VALUE,:new.M_TIME);
end;
--报警实况中是否已存在该监测点的该因子报警信息
if liveid>-1 then
update t_alarm_real r1 set r1.mvalue=:new.M_VALUE,r1.mtime=:new.M_TIME,r1.status=0 where r1.id=liveid;
else
--不存在则录入新的报警实况
insert into t_alarm_history(id,jcdbm,jcxmbm,mvalue,mtime)
values(SEQ_ALARM_REAL.NEXTVAL,:new.STATION_ID,:new.INFECTANT_ID,:new.M_VALUE,:new.M_TIME);
end if;
end if;
end if;

EXCEPTION
WHEN no_data_found THEN
null;

end TIG_MONITOR_ALARM;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值