CREATE TABLE `pr_user` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`user` varchar(255) DEFAULT NULL,
`dp` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
CREATE TABLE `pr_user_tmp` (
`user` varchar(255) DEFAULT NULL,
`dp` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP PROCEDURE IF EXISTS sys_user ;
CREATE PROCEDURE sys_user()
BEGIN
DECLARE done int;
DECLARE u VARCHAR(255);
DECLARE d VARCHAR(255);
DECLARE u_c CURSOR FOR SELECT user u,dp d from pr_user ORDER BY id;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
OPEN u_c;
c:LOOP
FETCH u_c INTO u,d;
if done=1 then
leave c;
ELSE
IF d=‘d1‘ THEN
INSERT INTO pr_user_tmp VALUES(u,d);
END if;
end if;
END LOOP c;
CLOSE u_c;
end;
CALL sys_user();
SELECT * from pr_user_tmp;