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

WBOY
Release: 2016-06-13 12:40:38
Original
864 people have browsed it

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

<br />
DELIMITER $$<br />
<br />
CREATE DEFINER=`root`@`localhost` PROCEDURE `pr_test3`()<br />
BEGIN  <br />
DECLARE p_username VARCHAR(20);  <br />
DECLARE p_email VARCHAR(20) ;    <br />
DECLARE Done INT;    <br />
#得到游标,选择老的表里面的username和email<br />
DECLARE rs CURSOR FOR SELECT username,email FROM  user LIMIT 100;  <br />
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET Done = 1;  <br />
  <br />
OPEN rs;<br />
FETCH NEXT FROM rs INTO p_username,p_email;  <br />
#开始遍历  <br />
REPEAT  <br />
IF NOT Done THEN  <br />
#执行需要的操作  <br />
  SELECT @p_username;<br />
#插入到新的库的表<br />
  INSERT INTO NEW_DB.`USER_ACCOUNT` (USERID,`PASSWORD`,`EMAIL`,`REGTIME`,`MODTIME`) VALUES (p_username,,'123456',p_email,NOW(),NOW());<br />
 #下一条<br />
 FETCH NEXT FROM rs INTO p_username,p_email;  <br />
END IF;  <br />
UNTIL Done END REPEAT;  <br />
CLOSE rs;  <br />
END$$<br />
DELIMITER ;<br />
Copy after login

游标
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template