Home >Backend Development >PHP Tutorial >使用游标将数据更新,陷入死循环,求解释

使用游标将数据更新,陷入死循环,求解释

WBOY
WBOYOriginal
2016-06-23 14:18:13981browse

数据迁移
要将老的数据库里面的数据导入到新的数据库。
数据表不一样,只是有些字段一样。
我要
将这个库里面的user 表的数据导入到
NEW_DB的`USER_ACCOUNT表,下面这样居然陷入了循环,运行了十几分钟

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'

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn