Oracle觸發器中select into報錯no_data_found異常處理
紅色部分為對查詢不到數據異常的處理
create or replace trigger TIG_MONITOR_ALarm
after insert on t_monitor_real_minute
for each row www.2cto.com
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 www.2cto.com (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 www.2cto.com (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;
您正在看的文章來自瘋狂軟件教育中心 www.fkjava.org
信息咨詢:Q564205990 星老師