通过存储过程批量更新数据:
代码:
BEGIN /*局部变量的定义 declare*/ declare aid VARCHAR(255) default 0 ; declare nicname int default 0; declare stop VARCHAR(2) default 0; declare i int default 0; declare cur CURSOR FOR (select nicename,id FROM pms_user WHERE id >160); declare CONTINUE HANDLER FOR SQLSTATE '02000' SET stop = null; /*开游标*/ OPEN cur; /*游标向下走一步,将查询出来的两个值付给定义的两个变量*/ FETCH cur INTO nicname,aid; /* 循环体 根据条件逐条更新user表 */ WHILE (stop is not null) DO UPDATE pms_user SET ttt='已更新' WHERE id = aid and nicename=nicname; SET i=i+1; /*游标向下走一步*/ FETCH cur INTO nicname,aid; END WHILE; CLOSE cur; return i; END