0 10:20:35 CREATE PROCEDURE pro_user4() BEGIN DECLARE a,b VARCHAR(20) ; DECLARE cur_t_user2
CURSOR FOR SELECT userName2,password2 FROM t_user2; DECLARE done INT DEFAULT FALSE; DECLARE CONTINUE HANDLER
FOR NOT FOUND SET done = TRUE; OPEN cur_t_user2; aaa:LOOP FETCH cur_t_user2 INTO a,b; IF
done THEN LEAVE aaa; END IF; INSERT INTO t_user VALUES(NULL,a,b); END LOOP aaa ; CLOSE cur_t_user2;
END Error Code: 1337. Variable or condition declaration after cursor or handler declaration
DELIMITER &&
CREATE PROCEDURE pro_user4()
BEGIN
DECLARE a,b VARCHAR(20) ;
declare done int default 0;
DECLARE cur_t_user2 CURSOR FOR SELECT userName2,password2 FROM t_user2;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN cur_t_user2;
aaa:LOOP
FETCH cur_t_user2 INTO a,b;
IF done THEN
LEAVE aaa;
END IF;
INSERT INTO t_user VALUES(NULL,a,b);
END LOOP aaa ;
CLOSE cur_t_user2;
END
&&
DELIMITER ;
将上述红色的那句放在蓝色的那句上面也会弹出如上的错误,但将自定义的非游标变量放在所有游标变量之前且保持上面红色那句代码在蓝色代码那句后面,编译通过。
参考:http://blog.163.com/danshiming@126/blog/static/1094127482015576349300/