日期:2014-05-17 浏览次数:20521 次
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `pr_test3`()
BEGIN
DECLARE p_username VARCHAR(20);
DECLARE p_email VARCHAR(20) ;
DECLARE Done INT;
#得到游标,选择老的表里面的username和email
DECLARE 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 ;