当前位置:网站首页>oracle和mysql批量Merge对比

oracle和mysql批量Merge对比

2022-07-05 09:37:00 51CTO

orm框架采用mybatis,本博客介绍一下批量合并merge用oracle和mysql来做的区别,

oracle merge合并更新函数的详细介绍可以参考我以前的博客

      
      
<!-- 批量更新新增关联信息 oracle-->
<insert id="batchSaveTipsRelatedConfig" databaseId="oracle" parameterType="com.extend.tipsConfig.model.TipsRelatedModel">
MERGE INTO t_tips_config_related A1
USING(<foreach collection="relatedTipsList" item="itm" separator="union">select #{itm.seq} seq ,
#{itm.tipsSeq} tipsSeq ,
#{itm.relaSeq} relaSeq,
#{itm.tipsContent} tipsContent
from dual
</foreach>) A2
ON(A1.tips_seq = A2.tipsSeq and A1.rela_seq = A2.relaSeq)
WHEN MATCHED THEN
UPDATE SET
A1.tips_content = A2.tipsContent
WHEN NOT MATCHED THEN
INSERT(seq , tips_seq , rela_seq, tips_content)
VALUES(A2.seq , A2.tipsSeq ,A2.relaSeq, A2.tipsContent)
</insert>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.

mysql方法:

      
      
<!-- 批量更新新增关联信息 mysql-->
<insert id="batchSaveTipsRelatedConfig" databaseId="mysql" parameterType="com.extend.tipsConfig.model.TipsRelatedModel">
REPLACE INTO t_tips_config_related(seq,tips_seq,rela_seq,tips_content)
VALUES<foreach collection="relatedTipsList" item="itm" separator=",">(#{itm.seq},
#{itm.tipsSeq},
#{itm.relaSeq},
#{itm.tipsContent})</foreach>
</insert>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.


原网站

版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://blog.51cto.com/u_15704340/5442402