mybatis Oracle 批量插入,批量更新

mybatis Oracle 批量插入,批量更新

传入的参数只要是list类型的参数就行了。。。。。。。。。。。。。。
1、批量插入

<insert id="insertBatch" parameterType="java.util.List">
    INSERT INTO T_CITY_INDEX(
    id,city_code
    )
    select SEQ_CITY_INDEX.NEXTVAL,cd.* from(
    <foreach collection="list" item="item" index="index"  close=")" open="(" separator="union">
        select
        #{item.cityCode,jdbcType=VARCHAR},
        #{item.cityName,jdbcType=VARCHAR}
        from dual
    </foreach>
    ) cd
</insert>

2、批量跟新

<update id="updateBatch"  parameterType="java.util.List">
    <foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";">
        update T_CITY_INDEX t
        set
        t.city_name= #{item.cityName,jdbcType=VARCHAR} ,
        t.district_name= #{item.districtName,jdbcType=VARCHAR} ,
        where t.id = #{item.id,jdbcType=NUMERIC}
    </foreach>
</update>

标签: mybatis, Oracle, 批量插入, 批量更新

猜你喜欢

转载自blog.csdn.net/qq_41344503/article/details/81507681