当前位置:主页 > 数据库 > Oracle >

解决Oracle批量修改问题

时间:2021-03-09 10:06:37 | 栏目:Oracle | 点击:

问题:根据唯一字段编码修改其它字段,修改部分数据,数量在上万条数据,数据大,一开始就卡死了!笨办法,一条一条修改不知可年可月啊。其他方法个人原因实在是无能为力。如下:

update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-2V';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-2W';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-2X';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-2Y';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-2Z';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-31';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-32';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-33';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-34';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-35';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-36';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-37';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-38';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-39';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-3A';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-3B';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-3C';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-3D';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-3E';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-3F';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-3G';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-3H';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-3I';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-3J';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-3K';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-3L';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-3M';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-3N';
update ka02_new set aka065=1,aka166=1 where aka060='X-P02CA-A010-A001-3O';
....

百度结果:百度了一下,很多解决方案,有的写的很粗糙,完全不理解,也许自己水平问题。有的是自己真的看不懂,个人水平跟不上。

解决方案:最后的解决办法,还是老办法,就是新建一张临时表(表B:a_2017 ),把所修改的唯一字段编码和修改后的数据放在B表。sql大体如下(原表A:ka02_new ,唯一字段aka060 ,修改的字段分别为aka065 和aka166 ):

update ka02_new b
  set b.aka065 =
    (SELECT a.aka065 FROM a_2017 a WHERE a.aka060 = b.aka060),
    b.aka166 =
    (SELECT a.aka166 FROM a_2017 a WHERE a.aka060 = b.aka060)
 WHERE b.aka060 in (SELECT a.aka060 FROM a_2017 a);

总结

您可能感兴趣的文章:

相关文章