1、错误描述
2、错误原因
BEGIN
DECLARE l_id INT;
DECLARE l_name VARCHAR(20);
DECLARE l_age INT;
DECLARE cur_stu CURSOR FOR SELECT t.id,t.name,t.age FROM t_stu_info t;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
OPEN cur_stu;
my_loop:LOOP
FETCH cur_stu INTO l_id,l_name,l_age;
IF done=1 THEN
LEAVE my_loop;
END IF;
END LOOP my_loop;
CLOSE cur_stu;
END
存储过程中使用的变量done未声明,却使用了3、解决办法
先对done变量进行声明,后使用
BEGIN
DECLARE l_id INT;
DECLARE l_name VARCHAR(20);
DECLARE l_age INT;
DECLARE done INT DEFAULT 0;
DECLARE cur_stu CURSOR FOR SELECT t.id,t.name,t.age FROM t_stu_info t;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
OPEN cur_stu;
my_loop:LOOP
FETCH cur_stu INTO l_id,l_name,l_age;
IF done=1 THEN
LEAVE my_loop;
END IF;
END LOOP my_loop;
CLOSE cur_stu;
END