Mybatis批量更新Oracle数据库

用foreach做批量更新的时候总是报错:

    <update id="updateList" parameterType="java.util.List">
		<foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";">
			UPDATE T_JRAQ_PGJBXXSZ set
			<if test="item.n_sfyx !=null">
			    N_SFYX=#{item.n_sfyx,jdbcType=DECIMAL}
			</if>
			WHERE
			N_PGJBXXBID=#{item.n_pgjbxxbid,jdbcType=DECIMAL}
		</foreach>
	</update>

 以下这种写法有效(经过测试):

        <update id="updateList" parameterType="list">
            update T_JRAQ_PGJBXXSZ
            <trim prefix="set" suffixOverrides=",">
             <trim prefix="N_SFYX =case" suffix="end,">
                 <foreach collection="list" item="i" index="index">
                         <if test="i.n_sfyx!=null">
                          when N_PGJBXXBID=#{i.n_pgjbxxbid} then #{i.n_sfyx}
                         </if>
                 </foreach>
              </trim>
             </trim>
            where
            <foreach collection="list" separator="or" item="i" index="index">
              N_PGJBXXBID=#{i.n_pgjbxxbid}
          </foreach>
        </update>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值