- create PROCEDURE changestateId(OUT count_num INT)
- BEGIN
- DECLARE num INT DEFAULT 100;
- DECLARE done INT DEFAULT 0;
- DECLARE uId INT;
- DECLARE cId INT;
- DECLARE sId INT;
- DECLARE thecur CURSOR FOR
- SELECT userId, id, iStateId from pr_clothing;
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
- SELECT COUNT(*) INTO num from pr_clothing;
- SET count_num = num;
- SELECT count_num;
- set num = 0;
- OPEN thecur;
- REPEAT
- FETCH NEXT FROM thecur INTO uId, cId, sId;
- if not done then
- -- SELECT uId;
- SET sId = sId - 9200 + 9200;
- UPDATE pr_clothing set iStateId = sId where userId = uId and id = cId;
- SET num = num + 1;
- end if;
- UNTIL done END REPEAT;
- CLOSE thecur;
- SELECT num;
- END
- -- set @pOUt = 1;
- -- CALL changestateId(@pOUt);

本文介绍了一个MySQL存储过程,用于批量更新数据库表pr_clothing中的状态ID字段iStateId。通过定义游标遍历每条记录,并对状态ID进行调整。该过程包括初始化变量、设置游标、处理数据及关闭游标等步骤。

195

被折叠的 条评论
为什么被折叠?



