delimiter //
# 创建一个存储过程
create procedure update_table_id()
begin
# 声明计数器
declare i int default 1;
# 声明截至数,本次是取表最后一个id
declare j int default (SELECT MAX(id) FROM t_place);
# 开始循环
num:loop
# 查询计数器记录的值
select i;
# 判断大于等于停止计数
if i > j then
leave num;
end if;
# 需要循环的语句
update t_place set history_id = REPLACE(UUID(),'-',''),is_replacement = 0 where id=i and history_id is NULL;
# 计数器自增1
set i = i + 1;
# 结束循环
end loop num;
end //
call update_table_id();
本文来自博客园,作者:栈,转载请注明原文链接:https://www.cnblogs.com/yyj-666/p/17271789.html
浙公网安备 33010602011771号