zoukankan      html  css  js  c++  java
  • Oracle之mergeInto

    ORACLE  实现存在时 - 更新,不存在时,插入
    1 MERGE INTO table B 
    2 USING (SELECT COUNT(*) AS QUNATUM FROM table C WHERE C.CROSSID = '20000031100804'AND C.LANEID = '' AND C.NEXTCROSSID = '') T 
    3 ON (T.QUNATUM > 0) 
    4 WHEN MATCHED THEN UPDATE SET B.SBBH = '',B.LANEID = '120',B.NEXTCROSSID = '20000031100805'
    5 WHEN NOT MATCHED THEN INSERT (B.SBBH, B.LANEID, B.NEXTCROSSID,B.CROSSID) VALUES ('','5','20000031100806','20000031100810') ;

    对应的Mybatis:

     1 <update id="mergeIntoLianeroadmapping" parameterType="java.lang.String">
     2         MERGE INTO table B
     3         USING (SELECT COUNT(C.CROSSID) AS QUNATUM FROM table C WHERE C.CROSSID = #{crossId}
     4         AND C.LANEID = #{laneId} AND C.NEXTCROSSID = #{nextCrossId}) T
     5         ON (T.QUNATUM > 0)
     6         WHEN MATCHED THEN
     7            UPDATE SET B.SBBH = '',B.LANEID = '6',B.NEXTCROSSID = #{nextCrossId}
     8         WHEN NOT MATCHED THEN
     9             INSERT (B.SBBH, B.LANEID, B.NEXTCROSSID,B.CROSSID) VALUES ('',#{laneId},#{nextCrossId},#{crossId})
    10 </update>
     1 merge语法是根据源表对目标表进行匹配查询,匹配成功时更新,不成功时插入。
     2 
     3 其基本语法规则是
     4 
     5 merge into 目标表 a
     6 
     7 using 源表 b
     8 
     9 on(a.条件字段1=b.条件字段1 and a.条件字段2=b.条件字段2 ……)  
    10 
    11 when matched then update set a.更新字段=b.字段
    12 
    13 when  not macthed then insert into a(字段1,字段2……)values(值1,值2……)
    往事如烟,余生有我.
  • 相关阅读:
    微软消息队列
    使用Memcached Provider客户端的increment()||decrement()操作小结
    SQL While And Sql Array
    好管理是成功的99%
    Javascript图片无缝滚动
    javascript数组复习
    前端面试题--js切换td中的值
    推荐使用:易企在线客服升级版
    drupal中根据不同的内容类型节点显示不同的样式
    defer和async(原生js学习)转
  • 原文地址:https://www.cnblogs.com/assistants/p/10593504.html
Copyright © 2011-2022 走看看