【指标统计】删除错误遥信
生活随笔
收集整理的這篇文章主要介紹了
【指标统计】删除错误遥信
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
查找指定時間范圍內的錯誤遙信
select occur_time, milli_second, alarm_type, result, content from scada_event_yx where occur_time > '2019-07-12 00:00:00' and occur_time < '2019-07-19 00:00:00' and alarm_type = 1 and result = 1;選擇其中一些,根據occur_time,alarm_type,result編寫SQL語句進行刪除操作。
以下是已經廢棄的舊版本
1. 創建待刪除記錄特征表
CREATE TABLE "SMARTSYS"."scada_event_yx_mark" ( "OCCUR_TIME" TIMESTAMP(0) NOT NULL, "OBJ_ID" BIGINT NOT NULL, "STATUS" INTEGER NOT NULL, "ALARM_TYPE" INTEGER NOT NULL, "CONTENT" VARCHAR(512), "ISDEL" INTEGER default 0) STORAGE(ON "SMART_HISTORY", CLUSTERBTR);2. 將指定時間范圍內的錯誤遙信找出來,將其特征記錄到特征表中
declareoccur_time_var TIMESTAMP;soe_time_var timestamp;obj_id_var bigint;status_var integer;content_var VARCHAR;cnt integer;Pcur CURSOR; beginOPEN Pcur FOR select distinct e.occur_time,e.obj_id,e.status,e.content from scada_event_yx e where rtu_type in (3,4,7,8) and alarm_type = 1 and occur_time between '2019-05-01' and '2019-05-02';LOOPFETCH Pcur INTO occur_time_var,obj_id_var,status_var,content_var;EXIT WHEN Pcur%NOTFOUND;execute immediate 'select count(*) from scada_event_yx where alarm_type = 3 and soe_time <=? and soe_time >= ? and obj_id = ? and status = ?;' into cnt using occur_time_var,occur_time_var-numtodsinterval(15,'second'),obj_id_var,status_var;if (cnt < 1) then--execute immediate 'delete from scada_event_yx where alarm_type = 1 and occur_time =? and obj_id = ? and status = ?;' into cnt using occur_time_var,obj_id_var,status_var;execute immediate 'insert into scada_event_yx_mark(alarm_type,occur_time,obj_id,status,content) values(1,?,?,?,?);' using occur_time_var,obj_id_var,status_var,content_var;end if;END LOOP;CLOSE Pcur; end;commit;3. 從特征表中手動標記確認要刪除的記錄:isdel=1
4. 從原始表中徹底刪除錯誤遙信記錄
delete from scada_event_yx where exists (select * from scada_event_yx_mark where isdel = 1 and scada_event_yx.occur_time=scada_event_yx_mark.occur_time and scada_event_yx.alarm_type=scada_event_yx_mark.alarm_type and scada_event_yx.status=scada_event_yx_mark.status); commit;5. 刪除特征表
drop table scada_event_yx_mark;總結
以上是生活随笔為你收集整理的【指标统计】删除错误遥信的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【指标统计】本区或跨区取WEB统计指标配
- 下一篇: 【指标统计】删除失败遥控