mysql中怎么定时调存储过程
1个回答
2014-11-15
展开全部
那就用游标吧,代码没测试,建议先用测试数据测试一下能不能正常运行
delimiter //
create procedure Calcu_MonTotal()
begin
DECLARE v_date varchar(16);
DECLARE v_total int;
DECLARE v_tagname varchar(32);
SELECT DATE_FORMAT( DATE_ADD( NOW( ) , INTERVAL '-1' MONTH ),'%Y-%m') into v_date;
DECLARE cursor c_Fetch
For select tagname,sum(daytotal)
FROM ribao
WHERE ddate> DATE_FORMAT( DATE_ADD( NOW( ) , INTERVAL '-1' MONTH ),'%Y-%m')
and ddate < DATE_FORMAT(NOW(),'%Y-%m') group by tagname;
DECLARE CONTINUE HANDLER FOR NOT FOUND set stopFlag=1;
OPEN c_Fetch;
REPEAT
FETCH c_Fetch INTO v_tagname,v_total;
begin
insert into yuetotal (tagname,ddate,yuetotal) values (v_tagname,v_date,v_total);
end;
UNTIL stopFlag = 1
END REPEAT;
CLOSE c_Fetch;
end
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询