mybatis+Oracle 批量插入数据,有数据做更新操作


<!-- 批量添加 -->
    <insert id="batchAdd" parameterType="java.util.List">
       merge into t_tabe_temp  fail
            using
            (
                <foreach collection="list" item="item" separator="union all">  <!-- 传入的集合参数 -->
                  select 
                     #{item.id, jdbcType=VARCHAR} id,
                       #{item.time, jdbcType=VARCHAR} time,
                 from dual         
               </foreach>
            ) t1
            on (fail.id= t1.id)  <!-- 关联的主键编号-->
            when matched then <!-- 如果存在就更新 -->
            update set  <!-- 注意,这里不要写set  id ==  xx  -->
            fail.time = t1.time,
            when not matched then  <!-- 不存在就插入数据 -->
              insert 
              (fail.id, fail.time)
              values
              (t1.id, t1.time)
    </insert>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM