我在mysql上有一个sql代码:
DELIMITER //
CREATE PROCEDURE proc()
main_block: BEGIN
DECLARE is_finished BOOLEAN DEFAULT FALSE;
DECLARE row_name VARCHAR(50) DEFAULT FALSE;
DECLARE row_id INT DEFAULT FALSE;
DECLARE cur CURSOR FOR SELECT `ID`, `Name` FROM `mytable`;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET is_finished = TRUE;
OPEN cur;
my_loop: REPEAT
FETCH cur INTO row_id, row_name;
IF row_id IS NULL THEN
LEAVE main_block;
END IF;
SET @query = concat('SELECT `ID` INTO @msg_id from ', row_name, '_msgs');
PREPARE run_query FROM @query;
EXECUTE run_query;
DEALLOCATE PREPARE run_query;
...
UNTIL is_finished
END REPEAT my_loop;
CLOSE cur;
END;
END //
mytable
包含三行,因此Repeat-Until应该可以运行三轮,但在EXECUTE run_query; DEALLOCATE PREPARE run_query;
is_finished
获得TRUE
后,循环在完成第一轮后结束。
如何在EXECUTE
变量上禁用is_finished
的效果?