mysql存储过程while遍历游标

更新时间:2023-06-08 09:09:38 阅读: 评论:0

mysql存储过程while遍历游标
DELIMITER $$
CREATE PROCEDURE queryEduTopologyPerformance(IN edu_id VARCHAR(50),OUT ebu_number_total INT ,
OUT upstream_total INT,OUT downstream_total INT,OUT alarm_number_total INT)
BEGIN
-- 定义变量
DECLARE ebuId VARCHAR(50);  -- 游标接收变量
DECLARE nowTime DATETIME; -- 当前时间
DECLARE beforeTwoMinuteTime DATETIME; -- 两分钟前的时间教案模板
DECLARE upstreamTemp INT; -- ebu上⾏流量临时变量
DECLARE downstreamTemp INT; -- ebu下⾏流量临时变量
DECLARE alarmTemp INT; -- ebu告警临时变量
DECLARE i INT DEFAULT 0;
-- 遍历数据结束标志
DECLARE done INT DEFAULT FALSE;
DECLARE cur CURSOR FOR SELECT ebu.id FROM  cap_ebu ebu,cap_edu edu WHERE ebu.edu_id = edu.id  AND edu.id = edu_id;
-- 将结束标志绑定到游标
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
-- 为变量赋值
SET ebu_number_total = 0;
SET upstream_total = 0;
形容可爱的词语SET downstream_total = 0;
SET alarm_number_total = 0;2019年清宫表
SET upstreamTemp = 0;
SET downstreamTemp = 0;
鸡蛋腐竹糖水
SET alarmTemp = 0;
SET nowTime = NOW();
字谜大全一年级SET beforeTwoMinuteTime = DATE_SUB(nowTime, INTERVAL 1 MINUTE);
SELECT COUNT(*) INTO ebu_number_total FROM  cap_ebu ebu,cap_edu edu WHERE ebu.edu_id = edu.id  AND edu.id = edu_id;
OPEN cur;
loop1: WHILE i<ebu_number_total DO -- 遍历开始
FETCH cur INTO ebuId; -- 获取游标⾥的ebuId值
亚麻色
-- 重置变量值
SET i = i + 1;
假日经济
SET upstreamTemp = 0 ;
SET downstreamTemp = 0;
SET  alarmTemp  = 0 ;
-- 计算总流量,总告警数
SELECT upstream INTO upstreamTemp FROM ebu_stream_view WHERE TIME >=beforeTwoMinuteTime  AND TIME <=nowTime  AND id = ebuId ORDER BY    SELECT downstream INTO downstreamTemp FROM ebu_stream_view WHERE TIME >=beforeTwoMinuteTime  AND TIME <=nowTime  AND id = ebuId ORD    SET upstream_total = upstream_total + upstreamTemp;
韭菜鸡蛋饺SET downstream_total = downstream_total + downstreamTemp;
SELECT alarmNumber INTO alarmTemp FROM current_alarm WHERE last_update_time >=beforeTwoMinuteTime AND last_update_time <=nowTime AND de    SET alarm_number_total = alarm_number_total + alarmTemp;
END WHILE loop1;
CLOSE cur;
END $$
DELIMITER ;

本文发布于:2023-06-08 09:09:38,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/901388.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:变量   游标   遍历
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图