DELIMITER $$DROP PROCEDURE IF EXISTS `testloop`$$CREATE PROCEDURE `testloop`()
BEGIN DECLARE uname VARCHAR(200) character set utf8;
DECLARE mname VARCHAR(200) character set utf8;
DECLARE userid int;
DECLARE tempid int default 0;
declare done int default 0;
DECLARE cur_rows cursor for (select id,name from naruto_users group by name having count(*) >1 limit 1);
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
/*游标*/
open cur_rows;
fetch cur_rows into userid,uname;/*WHILE done=0 do */
SELECT @tempid := `id`, @mname := `name` from naruto_users where name = uname order by id desc limit 1;
insert into test values (tempid,mname);
/*SELECT tempid = id,uname = name from naruto_users where name = uname order by id desc limit 1;
*/
/*update naruto_userbind set uid = userid where uid = tempid;
DELETE from naruto_users where id = tempid;
*/
fetch cur_rows into userid,uname;
/*select uname;*//*end while;*/CLOSE cur_rows;
END$$无论如何,那两个值是获取不到的.
直接输出select却能显示 奇怪了.
这个地方
可是这样的话 报错了呀You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':= `id`, mname := `name` from naruto_users where name = uname order by id desc l' at line 14
DELIMITER $$DROP PROCEDURE IF EXISTS `testloop`$$CREATE PROCEDURE `testloop`()
BEGIN DECLARE uname VARCHAR(200) character set utf8;
DECLARE mname VARCHAR(200) character set utf8;
DECLARE userid int;
DECLARE tempid int default 0;
declare done int default 0;
DECLARE cur_rows cursor for (select id,name from naruto_users group by name having count(*) >1 limit 1);
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;open cur_rows;
fetch cur_rows into userid,uname;SELECT @tempid := `id`, @mname := `name` from naruto_users where name = uname order by id desc limit 1;
insert into test values (@tempid,@mname);fetch cur_rows into userid,uname;CLOSE cur_rows;
END$$