DELIMITER $$
DROP PROCEDURE IF EXISTS `p3` $$
CREATE PROCEDURE p3()
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE table_name VARCHAR(255);
DECLARE stmt varchar(200);
DECLARE cur1 CURSOR FOR select table_name from information_schema.tables;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
CREATE PROCEDURE p3()
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE table_name VARCHAR(255);
DECLARE stmt varchar(200);
DECLARE cur1 CURSOR FOR select table_name from information_schema.tables;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN cur1;
REPEAT
FETCH cur1 INTO table_name;
select table_name;
UNTIL done = 1
END REPEAT;
CLOSE cur1;
END $$
FETCH cur1 INTO table_name;
select table_name;
UNTIL done = 1
END REPEAT;
CLOSE cur1;
END $$
DELIMITER ;
查询出来的结果都为空, 最后发现变量table_name与游标定义中的table_name重复,修改变量table_name为其它的名字。 但具体内在的发生机制还不太清楚。