MyBatis批量操作SQL

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/thebigdipperbdx/article/details/82263112

适用范围

  • 适用Oracle数据库

批量插入

<insert id="addGroupInfoBatch" useGeneratedKeys="true" parameterType="java.util.List">
     INSERT INTO group_info (userid,liveuserid,groupid,nickname,headpic)
     VALUES
     <foreach collection="list" item="info" index="index"
         separator=",">
         (#{info.userid},#{info.liveuserid},#{info.groupid},#{info.nickname},#{info.headpic})
     </foreach>
 </insert> 

批量更新操作一

<update id="updateRookieCustomer" parameterType="map">
    <if test="birdList!=null and birdList.size()>0">
        UPDATE TAB_ROOKIECUSTOMER SET ISPUSH = 1,pushdate = sysdate
        <where>
            <foreach collection="birdList" item="cus" open="( " separator=") or (" close=" )">
                SELLERID = #{cus.custNo} AND BRANCHCODE = #{cus.orgCode}
            </foreach>
        </where>
    </if>
 </update>

批量更新操作二

<update id="updateCustomer" parameterType="map" >
    <if test="custNo!=null and custNo.size()>0">
        update tab_vip客户资料表 set ISPUSH = 1,pushdate = sysdate
        WHERE 客户编号 in
        <foreach item="item" index="index" collection="custNo" open="(" separator="," close=")">
            #{item}
        </foreach>
    </if>
</update>

批量更新操作三

<update id="batchUpdate" parameterType="java.util.List">
    update demo_table
    set field1 = 
    <foreach collection="list" item="item" open="case " close=" end">
        when field2 = #{item.value2} AND field3 = #{item.value3} then #{item.value1}
    </foreach>
    <where>
        <foreach collection="list" item="item" open="( " separator=") or (" close=" )">
        field2 = #{item.value2} AND field3 = #{item.value3}
    </foreach>
    </where>
 </update>

批量更新操作四

<update id="updateRookieCustomer" parameterType="map">
    <if test="birdList!=null and birdList.size()>0">
        UPDATE TAB_ROOKIECUSTOMER SET ISPUSH = 1,pushdate = sysdate
        WHERE SELLERID||'@@'||BRANCHCODE IN
        <foreach collection="birdList"  index="index" item="cus" open="(" separator="," close=")">
             #{cus.custNo}||'@@'||#{cus.orgCode}
        </foreach>
    </if>
</update>

猜你喜欢

转载自blog.csdn.net/thebigdipperbdx/article/details/82263112