时间:2021-07-01 10:21:17 帮助过:15人阅读
DELIMITER $$CREATE DEFINER=`root`@`localhost` PROCEDURE `pr_test3`()BEGIN DECLARE p_username VARCHAR(20); DECLARE p_email VARCHAR(20) ; DECLARE Done INT; #得到游标,选择老的表里面的username和emailDECLARE rs CURSOR FOR SELECT username,email FROM user LIMIT 100; DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET Done = 1; OPEN rs;FETCH NEXT FROM rs INTO p_username,p_email; #开始遍历 REPEAT IF NOT Done THEN #执行需要的操作 SELECT @p_username;#插入到新的库的表 INSERT INTO NEW_DB.`USER_ACCOUNT` (USERID,`PASSWORD`,`EMAIL`,`REGTIME`,`MODTIME`) VALUES (p_username,,'123456',p_email,NOW(),NOW()); #下一条 FETCH NEXT FROM rs INTO p_username,p_email; END IF; UNTIL Done END REPEAT; CLOSE rs; END$$DELIMITER ;
因为你加了limit 100的限制,怎么也不可能出现SQLSTATE '02000'