Navicat创建事件不执行的情况?

41 篇文章 0 订阅

最近写了个存储过程,配合事件使用,任务:每五分钟刷新表格的数据

过程:

BEGIN
	DECLARE v_startTime BIGINT;
	DECLARE v_step INT;
	DECLARE i int DEFAULT 1;
	DECLARE v_endTime BIGINT;
	DECLARE v_date TIMESTAMP;
	DECLARE v_time varchar(20);

	set v_step = 60*5;#五分钟
	set v_startTime = DATE_FORMAT(CURRENT_DATE() ,'%Y%m%d') * 1000000;
	set v_endTime = v_startTime;

  set autocommit=false;
  delete from ts_user_onduty_history;
	ALTER TABLE ts_user_onduty_history AUTO_INCREMENT=1;
	delete from ts_user_onduty_xaxis;
# select DATEDIFF(DATE_FORMAT(CURRENT_DATE() ,'%Y%m%d') * 1000000,CURRENT_TIMESTAMP())
	#五分钟 
	while i<24*(60/5) and v_endTime<DATE_FORMAT(CURRENT_TIMESTAMP(),'%Y%m%d%H%i%s') DO
		set v_date = FROM_UNIXTIME(UNIX_TIMESTAMP(v_startTime) + i * v_step);
		set v_endTime = DATE_FORMAT(v_date,'%Y%m%d%H%i%s') + 59;

		set v_time = DATE_FORMAT(v_date,'%H:%i');
		insert into ts_user_onduty_xaxis(x) values(v_time);
		insert into ts_user_onduty_history(area_id,area_name,dept_id,dept_name , data_count, data_time)
		select area_id,area_name,dept_id,dept_name ,count(*) data_count,v_time data_time
		from (
			select user_id,max(pass_datetime) max_pass_datetime from view2_pass_record_curdate where company_id=1 and pass_datetime BETWEEN v_startTime and v_endTime group by user_id 
		) t , view2_pass_record_curdate a 
		where a.user_id=t.user_id and a.pass_datetime = max_pass_datetime and device_direction=1 and company_id=1 and a.user_id>0
		group by area_id,area_name,dept_id,dept_name;
		
		set i = i+1;
		#周文20180706
		#IF i> 24*12 THEN  set i = 1;delete from ts_user_onduty_history;delete from ts_user_onduty_xaxis; end if;
	end WHILE;

	commit;
	set autocommit=true;
END

事件:

定义:

计划:

不执行的原因是这里,不支持5 -MINNUTE搭配。

正确的方式如下:


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值