转:http://blog.itpub.net/29900383/viewspace-1284128/
大家可以看看:http://blog.sina.com.cn/s/blog_5d25646e0100qu17.html的内容,然后我再补充一点:
新建两张table :test_source和test_target,他们的数据分别如下:
SQL> select * from test_source;
NAME ID
---------- ----------
P3 74834
P4 74835
luo 8
P1 74832
P2 74833
zhi 8
SQL> select name ,id from test_target;
NAME ID
---------- ----------
P3*** 74834
P4*** 74835
luo** 8
P1*** 74832
P2*** 74833
zhi** 8
SQL> merge into test_target
2 using test_source
3 on (test_source.id = test_target.id)
4 when matched then update set test_target.name = test_source.name
5 when not matched then insert values(test_source.name,test_source.id);
using test_source
*
第 2 行出现错误:
ORA-30926: 无法在源表中获得一组稳定的行
---------------------哈哈,报错了,大家想想为什么呢?-----------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
解答如下:
首先我们要知道merge into存在的意义是什么!!!
使用merge into 是为了根据匹配条件on(condition)利用table_source 的数据更新合并table_target的数据。
merge into 的内部处理是将table_source 的每一条记录和table_target的每一条记录对比匹配,匹配到符合条件的 记录就会进行修改,匹配不到的话就会insert。如果table_source的匹配列中有重复值的话,等到第二次重复的列值匹配的时候,就会将第一次的update后的值再一次update,就是说合并后的table_target中会丢失在table_source中的记录!!!如果记录丢失的话,两表合并的意义何在?!!因此我们使用merge into要注意:源表匹配列中不能有重复值,否则无法匹配(报错! )。
-----------------------------------------------------------------------------------------------------------------我们可以上面将重复的列值去掉试试:
SQL> delete from test_source where name = 'zhi';
已删除 1 行。
SQL> merge into test_target
2 using test_source
3 on (test_source.id = test_target.id)
4 when matched then update set test_target.name = test_source.name
5 when not matched then insert values(test_source.name,test_source.id);
6 行已合并。
---------------这回就何合并成功了。
相关推荐
有关表死锁的详细图片 博文链接:https://meteor-1988.iteye.com/blog/1568695
源配置 resource_types :- name : merge-request type : docker-image source : repository : mastertinner/gitlab-merge-request-resourceresources :- name : repo-mr type : merge-request source : uri : ...
npm-merge-driver安装 自动合并package-lock.json冲突的软件包。 很大程度上基于 ,在软件包安装时进行自动设置,并且只有一个小的依赖项来进行ci检查。 用生成的目录 安装 安装运行 npm i --save-dev npm-...
当版本比较在范围内时,自动合并Dependabot PR。 注意: Dependabot将等到所有状态检查通过后再进行合并。 这是Dependabot本身的功能,而不是此Action。 用法 name : auto-merge on : pull_request : jobs : auto...
Mybatis批量foreach merge into的用法,这是介绍Mybatis批量foreach merge into的用法的文档
SSDT恢复的程序源 参考调试信息: Linking f:\driver\3 directory ******************** nmake.exe /c BUILDMSG=Stop. -i LINKONLY=1 NOPASS0=1 NTTEST= UMTEST= 386=1 link -out:.\i386\DrvTest.sys -machine:...
创建一个描述您的输入和输出的config.yml文件。 # config.yml clips : - input : video.mp4 output : merged.mp4 clips : - time : 00:05-00:10 - time : 00:15-00:20 # Example directory: /Videos -...
K-DBSCAN has two phases: first, it divides all data objects into different density levels to identify the different natural densities present in the dataset; then it extracts the clusters using a ...
主要类是pybigquery_merge_into.merge_clause.MergeInto() 。 例子 >> > query = MergeInto ( target = target , source = source , onclause = target . c . t1 == source . c . s1 , when_clauses = [ ...
关于Oracle中merge into的用法,比较实用哦
Oracle中merge into的使用 很有用的哦 学习一下
与beyondcompare工具差不多的使用方式,winmerge是开源免费版。当您有两个以上的内容相似的文字文件时,WinMerge就可以立刻派上用场,帮您检查两个...WinMerge会将两个文件内容做比对,并在相异之处以高亮度的方式显示
merge-table HTML表格设计器可以快速的可视化设计一个表格,可以对单元格进行合并,拆分,添加,删除以及设置样式等操作,API简单易懂 ...addRowTop 在当前选中的单元格上方添加行MergeTable.addRowTop(); addRowBot
npm install postcss-merge-longhand --save 例子 将速记属性合并为速记; 使用margin , padding和border 。 有关更多示例,请参见。 输入 h1 { margin-top : 10 px ; margin-right : 20 px ; margin-bottom : ...
创建一个新的.github/workflows/merge-me.yaml文件: name : Merge me! on : workflow_run : types : - completed workflows : # List all required workflow names here. - ' Continuous Integration ' ...
merge-chance.info代码这是页面,您可以在其中检查GitHub上您喜欢的开源项目的成功率。 如果只想在本地为给定的回购绘制一些图,请使用scripts目录中的scripts 。建立与设定您将需要一个GitHub令牌,以便从GitHub ...
这是设计使然,因为通常一列是一个字段,一行是一个记录-与在记录中多字段具有相同的值相比,多记录在一个字段中具有相同的值更为合理。 用法 // Node.js let MarkdownIt = require ( 'markdown-it' ) , ...
WinMerge-2.16.8-x64-Setup.exe
Merge into写法,含两种,带实例说明
非常经典的SQL经验,适合于数据库初学者及长期从事软件开发者