我有一个杀死睡眠进程的程序,但循环继续运行,我没有得到结果。循环继续运行。
DELIMITER $$
CREATE PROCEDURE `uKillSleepingSessions`(v_time INT )
BEGIN
DECLARE no_more_rows INT DEFAULT 0;
DECLARE loop_cntr INT DEFAULT 0;
DECLARE num_rows INT DEFAULT 0;
DECLARE V_ID bigint(4);
DECLARE v_time INT;
DECLARE my_cur CURSOR FOR
SELECT ID
FROM information_schema.PROCESSLIST PL
WHERE PL.COMMAND='Sleep' AND DB='test'
AND PL.TIME = v_time ;
DECLARE CONTINUE HANDLER FOR 1329
SET no_more_rows = 1;
OPEN my_cur;
SET num_rows = FOUND_ROWS();
IF
num_rows > 0 THEN
FETCH my_cur
INTO V_ID;
END IF;
the_loop: LOOP
IF no_more_rows = 1 THEN
CLOSE my_cur;
LEAVE the_loop;
END IF;
IF
num_rows > 0 THEN
SET @sql= CONCAT("KILL ",V_ID);
PREPARE s1 FROM @sql;
EXECUTE s1;
DEALLOCATE PREPARE s1;
END IF;
SET loop_cntr = loop_cntr + 1;
END LOOP the_loop;
END
请建议我哪里错了。我该如何修改它。可以修改 proc 以处理未知线程。谢谢