merge into_目标表匹配列重复与源表匹配表重复的区别

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就会报错,因为不知用源表哪条记录来更新目标表的数据                           

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9240380/viewspace-750968/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/9240380/viewspace-750968/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值