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