【指标统计】删除失败遥控

1. 创建待删除记录特征表
CREATE TABLE "SMARTSYS"."scada_event_yk_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. 将指定时间范围内的失败遥控找出来,将其特征记录到特征表中
declare
	occur_time_var TIMESTAMP;
	soe_time_var timestamp;
	obj_id_var bigint;
	status_var integer;
	content_var VARCHAR;
	cnt integer;
	Pcur CURSOR;
begin
	OPEN Pcur FOR select distinct e.occur_time,e.obj_id,e.status,e.content from scada_event_yk e 
		where rtu_type in (3,4,7,8) and alarm_type = 4 and status = 16 and occur_time between '2019-04-28' and '2019-05-02';
	LOOP
		FETCH Pcur INTO occur_time_var,obj_id_var,status_var,content_var;
		EXIT WHEN Pcur%NOTFOUND;
		execute immediate 'select count(*) from scada_event_yk where alarm_type = 4 and status = 17 and occur_time <=? and occur_time >= ? and obj_id = ?;' into cnt using occur_time_var+numtodsinterval(30,'second'),occur_time_var,obj_id_var;
		if (cnt < 1) then
			--execute immediate 'delete from scada_event_yk 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_yk_mark(alarm_type,occur_time,obj_id,status,content) values(4,?,?,?,?);' 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_yk where exists (select * from scada_event_yk_mark where isdel = 1 and scada_event_yk.occur_time=scada_event_yk_mark.occur_time and scada_event_yk.alarm_type=scada_event_yk_mark.alarm_type and scada_event_yk.status=scada_event_yk_mark.status);
commit;
5. 删除特征表
drop table scada_event_yk_mark;
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

皓月如我

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值