oracle 批量更新问题

时间:2021-03-10 20:39:15
有3张表,一张表a1是 有字段A ,B 另外一张表b1有字段A,B,等字段,表c1有字段B,等字段,以A表为基础更新B表C表,其中表a1表A列数据无重复;b1表数据A列和和a1表B列数据相关联;c1表数据B列和b1表中的B列相关联,现要更新B表和C表,表例如:
表a1       A               B         
           00001       DAS         
           00002        SDF         
           00003        ASD          
           00004       KJHF          
           00005      JKLK       
           .....       ...
表b1      A             B      ...............        
          00001      DGGGD     .............        
          00001      GDGDG      ...............        
          00001     CBCBCVB    .............         
          00002      QEQEWQE  ..........       
          00002      NVBNVBN     .............       
          00002     QWDFSA    ...............       
          00003     NVNVBNN    .............         
          00003     VBCGFG  ..........       
          00004      FSDF     .............       
          00004      DASDA    ...............       
          00005      FDSFS    .............         
          00003      SDFFSD  ..........       
          00003      SFFSD    .............          
          00004      SDDSFD    ...........
表c1    B                C              D  ...... 
       DGGGD       .............      
       GDGDG       ...............       
       DASDA         ...............       
       FDSFS        .............  
更新的结果需要是:
表B      A             B       
         00001      DAS       
         00001      DAS       
         00001       DAS         
         00002      SDF         
         00002     SDF         
         00002     SDF           
         00003     ASD           
         00003     ASD       
         00004      KJHF       
         00004      KJHF       
         00005      JKLK         
         00003     ASD         
         00003      ASD          
         00004      KJHF
表c1    B                C              D  ......  
       DAS          .............      
       DAS          ...............      
       KJHF         ...............       
       JKLK        .............  
    跪求更新b1和c1表的sql 语句。 请各位高手帮忙 

1 个解决方案

#1


update c1 set b=(select a1.b from a1,b1 where a1.a=b1.a and b1.b=c1.b);
update /*+ parallel(b1,2) */ b1 set b=(select b from a1 where a1.a=b1.a);

供参考

#1


update c1 set b=(select a1.b from a1,b1 where a1.a=b1.a and b1.b=c1.b);
update /*+ parallel(b1,2) */ b1 set b=(select b from a1 where a1.a=b1.a);

供参考