zoukankan      html  css  js  c++  java
  • oracle merge 目标表以及源表存在重复列的问题(转)

    SQL> select * from t_source;                                                                                             
                                                                                                                             
                                          A                                       B                                          
    --------------------------------------- ---------------------------------------                                          
                                          1                                       1                                          
                                          2                                       2                                          
                                                                                                                             
    SQL> select * from t_target;                                                                                             
                                                                                                                             
                                          A                                       B                                          
    --------------------------------------- ---------------------------------------                                          
                                          2                                      34                                          
                                          2                                    3999                                          
                                                                                                                             
    SQL> merge into t_target using t_source on (t_source.a=t_target.a) when matched then update set t_target.b=t_source.b;   
                                                                                                                             
    Done                                                                                                                     
                                                                                                                             
    SQL> select * from t_target;                                                                                             
                                                                                                                             
                                          A                                       B                                          
    --------------------------------------- ---------------------------------------                                          
                                          2                                       2                                          
                                          2                                       2                                          
                                                                                                                             
    SQL> commit;                                                                                                             
                                                                                                                             
    Commit complete                                                                                                          
                                                                                                                             
    小结:1,对于merge,目标表如果匹配列重复,但源表匹配不重复,会用源表表列新目标表的数据                                     
          2,反之,如果源表匹配列重复,此时merge就会报错,因为不知用源表哪条记录来更新目标表的数据 

     转自   

     http://blog.itpub.net/9240380/viewspace-750968/

  • 相关阅读:
    [Swift系列]002-基础语法
    [Swift系列]001-入门准备
    navicat连接服务器Mysql 忘记密码 ------- 查看密码
    Elasticsearch 7.10.1 尝鲜笔记
    java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy 排查解决
    nginx TCP 代理& windows傻瓜式安装
    python项目出现的问题 Microsoft Visual C++ 14.0 is required解决方法
    前端使用crypto.js进行加密
    xcopy 高级使用
    高并发解决方案-概念知识
  • 原文地址:https://www.cnblogs.com/SamuelSun/p/6541133.html
Copyright © 2011-2022 走看看