DELIMITER $$ #定义结束标志 DROP PROCEDURE IF EXISTS `pr_add`;$$ #创建存储过程 CREATE PROCEDURE `pr_add`() BEGIN declare n int default 0; declare bb int; DECLARE cur_1 CURSOR FOR SELECT action_id FROM useraction where uid=xxx;//取得游标,相当于数字的key DECLARE CONTINUE HANDLER FOR NOT FOUND SET n = 1;//如果记录取完,游标设置为1; OPEN cur_1; FETCH cur_1 INTO bb; while n<>1 do replace into useraction set action_id=bb,uid=xxx; FETCH cur_1 INTO bb; /*取下一条记录,游标每取一次会自动向后进一*/ end while; close cur_1; END$$ DELIMITER ; #调用存储过程 CALL pr_add();