Home >Database >Mysql Tutorial >mysql procedure-关于mysql5.6存储与游标的问题
mysql proceduremysqlmysql严重问题mysql event
如下是我的过程,不解的是当我把从游标里的任何一列当做判断结束游标条件时,无论何时它都为空,但它确确实实可以循环完,百思不得其解。
例如 WHILE ( TYPE IS NOT NULL ) 。 这里的type永远都为空。
再如果我将任意一列 , event_value 当做while 条件 event_value 同样为空。
在此跪求大鸟解答了。
DELIMITER $$
CREATE PROCEDURE test( IN event_value_name VARCHAR(20) , IN datestr VARCHAR(20) , IN start_date DATETIME , IN end_date DATETIME )
BEGIN
DECLARE temp VARCHAR(10) DEFAULT "";
DECLARE temps VARCHAR(200) DEFAULT "";
DECLARE report_tim VARCHAR(100) DEFAULT "";
DECLARE TYPE VARCHAR(50);
DECLARE event_value VARCHAR(50);
DECLARE source VARCHAR(50);
DECLARE event_name VARCHAR(50);
DECLARE COT VARCHAR(50);
DECLARE allrow CURSOR FOR SELECT tev.event_value,tev.source,tev.event_name,COUNT(*) AS COT,tev.type,DATE_FORMAT(tev.report_time,'%Y-%m-%d') report_tim FROM ts_event_value tev
WHERE tev.name=event_value_name AND tev.report_time BETWEEN start_date AND end_date
GROUP BY tev.event_value,tev.source,tev.event_name,tev.type,report_tim ORDER BY COT DESC LIMIT 15 ;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET TYPE = NULL;
OPEN allrow;
/*allrowloop:LOOP*/
FETCH allrow INTO event_value,source,event_name,COT,TYPE,report_tim;
IF datestr = "all" THEN
<code> WHILE ( TYPE IS NOT NULL ) DO SELECT s.name INTO temp FROM statistical s WHERE s.name = event_value_name AND s.source = source AND s.event_name = event_name AND s.event_value = event_value AND s.zt = "all"; IF temp = "" OR temp IS NULL THEN INSERT INTO statistical VALUES (source,event_name,event_value,COT,event_value_name,report_tim,"all"); ELSE UPDATE statistical s SET s.cot = s.cot + COT WHERE s.name = event_value_name AND s.source = source AND s.event_name = event_name AND s.event_value = event_value AND s.zt = "all"; END IF; FETCH allrow INTO event_value,source,event_name,COT,TYPE,report_tim; END WHILE; END IF; COMMIT; SELECT event_value,source,event_name,COT,temp; /*SELECT temps;*/ /*END LOOP allrowloop;*/CLOSE allrow;</code>
END;
$$
DELIMITER ;