Mysql的存储过程修改表的数据

把所有的记录中的周数进行加52  一共十三万条的数据

思路:

  • 先查询出来,把结果进行保存;
  • 把进行使用update进行更新;
create procedure changeweek2(in id_sum int) 
 begin 
	 declare id_count int default 1; 
	 declare week_num int default 1; 
	 while id_count<=id_sum do 
		 select week_in_year into week_num from offline_sc_20_mod_ST_copy where id=id_count; 
		 update offline_sc_20_mod_ST_copy set week_in_year=week_num+52 where id=id_count; 
		 set id_count=id_count+1; 
	 end while; 
 end; 
 call changeweek2(136507); 
发布了658 篇原创文章 · 获赞 73 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/fujian9544/article/details/103966077
今日推荐