oracle和mysql批量Merge对比

2022-05-07 16:55:30 浏览数 (1)

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

oracle merge合并更新函数的详细介绍可以参考我以前的博客:https://cloud.tencent.com/developer/article/1399414

oracle方法:

代码语言:javascript复制
<!-- 批量更新新增关联信息 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>

mysql方法:

代码语言:javascript复制
<!-- 批量更新新增关联信息 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>

0 人点赞