mysql批量更新数据,即:循环select记录然后更新某一字段
/*判断是否存在,如果存在就删除*/drop procedure if exists tempProcedure_Test;/*取一个系统中绝对不会用到的存储过程名称*//*创建临时存储过程*/create procedure tempProcedure_Test()BEGINdeclare isDone int default 0; /*判断是否还有记录*/declare intNumber i
·
/*判断是否存在,如果存在就删除*/
drop procedure if exists tempProcedure_Test;/*取一个系统中绝对不会用到的存储过程名称*/
/*创建临时存储过程*/
create procedure tempProcedure_Test()
BEGIN
declare isDone int default 0; /*判断是否还有记录*/
declare intNumber int default 30000;/*用于自增的变量*/
declare tempId char(36); /*每条记录循环时的临时ID*/
declare folderIds cursor for select A.ID from mus_gateway_deduct_transaction as A;/*取出来所有需要循环的数据*/
declare continue handler for not FOUND set isDone = 1;/*如果不存在就设置为1,即为true*/
open folderIds; /*OPEN*/
REPEAT /*开始循环数据*/
fetch folderIds into tempId;
if not isDone THEN
update mus_gateway_deduct_transaction set id=intNumber where id=tempId;
set intNumber=intNumber+1;
end if;
until isDone end repeat;
close folderIds; /*CLOSE,对应上面的open folderIds;*/
END;
call tempProcedure_Test();/*调用下这个临时的存储过程*/
drop procedure tempProcedure_Test; /*使用完毕后要删除垃圾*/
drop procedure if exists tempProcedure_Test;/*取一个系统中绝对不会用到的存储过程名称*/
/*创建临时存储过程*/
create procedure tempProcedure_Test()
BEGIN
declare isDone int default 0; /*判断是否还有记录*/
declare intNumber int default 30000;/*用于自增的变量*/
declare tempId char(36); /*每条记录循环时的临时ID*/
declare folderIds cursor for select A.ID from mus_gateway_deduct_transaction as A;/*取出来所有需要循环的数据*/
declare continue handler for not FOUND set isDone = 1;/*如果不存在就设置为1,即为true*/
open folderIds; /*OPEN*/
REPEAT /*开始循环数据*/
fetch folderIds into tempId;
if not isDone THEN
update mus_gateway_deduct_transaction set id=intNumber where id=tempId;
set intNumber=intNumber+1;
end if;
until isDone end repeat;
close folderIds; /*CLOSE,对应上面的open folderIds;*/
END;
call tempProcedure_Test();/*调用下这个临时的存储过程*/
drop procedure tempProcedure_Test; /*使用完毕后要删除垃圾*/
更多推荐
已为社区贡献1条内容
所有评论(0)