merge into语句的使用
生活随笔
收集整理的這篇文章主要介紹了
merge into语句的使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
merge語法是根據源表對目標表進行匹配查詢,匹配成功時更新,不成功時插入。其基本語法規則是merge into 目標表 ausing 源表 bon(a.條件字段1=b.條件字段1 and a.條件字段2=b.條件字段2 ……) when matched then update set a.更新字段=b.字段when not macthed then insert into a(字段1,字段2……)values(值1,值2……)變種寫法①,只更新:merge into 目標表 ausing 源表 bon(a.條件字段1=b.條件字段1 and a.條件字段2=b.條件字段2 ……) when matched then update set a.更新字段=b.字段,a.更新字段2=b.字段2……變種寫法②,只插入:merge into 目標表 ausing 源表 bon(a.條件字段1=b.條件字段1 and a.條件字段2=b.條件字段2 ……) when not macthed then insert into a(字段1,字段2……)values(值1,值2……)注:條件字段不可更新對于Oracle來說,merge是9i新增的語法,在10g進行了一些增強,如下:測試環境:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0①條件操作:merge into 目標表 ausing 源表 bon(a.條件字段1=b.條件字段1 and a.條件字段2=b.條件字段2 ……) when matched then update set a.更新字段=b.字段 where 限制條件when not macthed then insert into a(字段1,字段2……)values(值1,值2……) where 限制條件舉例:merge into test_merge a
using test b
on(a.no=b.no)
when matched then update set a.no2=b.no2 where a.no<>1
when not matched then insert values(b.no,b.no2) where a.no<>100當然也支持變種①②的寫法②刪除操作merge into 目標表 ausing 源表 bon(a.條件字段1=b.條件字段1 and a.條件字段2=b.條件字段2 ……) when matched then update set a.更新字段=b.字段delete where b.字段=xxx舉例:merge into test_merge a
using test b
on(a.no=b.no)
when matched then update set a.no2=b.no2 where a.no<>1
delete
where b.no=14
?
轉載于:https://www.cnblogs.com/lxnlxn/p/7808174.html
總結
以上是生活随笔為你收集整理的merge into语句的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 对象(三)
- 下一篇: 【转】javascript中的LHS与R