Mybatis中解决Oracle11g 不能在同一行执行多条命令问题(报错ora-00911)

        在Mybatis实现批量更行操作时,<foreach>标签实现,实质就是将多条sql拼接后让数据库执行,然后Oracle11g是不支持在同行执行多条命令的。所以要做特殊处理。

一,未处理代码

<update id="saveNos" parameterType="java.util.List">
        <foreach collection="list" item="item" index="index" separator=";" open="" close="">
            update matchtable
            <set>
                <if test="item.subtIds != null">
                    SUB_IDS = #{item.subIds, jdbcType=VARCHAR},
                </if>
                <if test="item.subNames != null">
                    SUB_NAMES = #{item.subNames, jdbcType=VARCHAR}
                </if>
            </set>
            where id = #{item.id, jdbcType=VARCHAR}
        </foreach>
  </update>

这中mapper最后发到数据库中的sql脚本是将所有的sql拼接在一行发给数据库,这样Oracle11g运行是会报错误的ora-00911。

二,特殊处理

<update id="saveNos" parameterType="java.util.List">
        <foreach collection="list" item="item" index="index" separator=";" open="begin" close=";end;">
            update matchtable
            <set>
                <if test="item.subtIds != null">
                    SUB_IDS = #{item.subIds, jdbcType=VARCHAR},
                </if>
                <if test="item.subNames != null">
                    SUB_NAMES = #{item.subNames, jdbcType=VARCHAR}
                </if>
            </set>
            where id = #{item.id, jdbcType=VARCHAR}
        </foreach>
  </update>

即用,begin ..........;end;命令块包裹一下就可以了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值