mybatis批量插入记录到Oracle

本文介绍了使用MyBatis进行批量数据插入的方法,包括使用序列作为主键和UUID作为主键两种情况,并展示了具体的XML配置文件代码。

序列为主键:

<insert id="insertAll" parameterType="java.util.List">
        
        <selectKey resultType="int" keyProperty="id" order="BEFORE"> 
            SELECT SEQ_LCSS_DRIVER_ROUTE.NEXTVAL FROM DUAL 
        </selectKey>  
        
        insert into 
            LCSS_DRIVER_ROUTE (id,route_id,shift_id,place,train_id,call_time,attendance_time,delivery_time,playing_time,returning_time,kilometers)
        select SEQ_LCSS_DRIVER_ROUTE.NEXTVAL, A.* from
        (  
          <foreach collection="list" item="item" separator="union all">  
              select 
                  #{item.routeId, jdbcType=VARCHAR} as route_id,
                  #{item.shiftId, jdbcType=VARCHAR} as shift_id,
                  #{item.place, jdbcType=VARCHAR} as place,
                #{item.trainId, jdbcType=VARCHAR} as train_id,
                #{item.callTime, jdbcType=VARCHAR} as call_time,
                #{item.attendanceTime, jdbcType=VARCHAR} as attendance_time,
                #{item.deliveryTime, jdbcType=VARCHAR} as delivery_time,
                #{item.playingTime, jdbcType=VARCHAR} as playing_time,
                #{item.returningTime, jdbcType=VARCHAR} as returning_time,
                #{item.kilometers, jdbcType=INTEGER} as kilometers
              from dual
          </foreach>  
        ) A
             
    </insert>

uuid为主键:

<insert id="insertWorkGroupList" parameterType="java.util.List">
        insert into 
            LCSS_WORK_GROUP (ID, GROUP_ID, SHIFT_ID, USER_ID, CONDUCTOR_ID)
        <foreach collection="list" item="item" index="index" separator=" UNION ALL ">
        SELECT 
            SYS_GUID(),#{item.groupId,jdbcType=VARCHAR},#{item.shiftId,jdbcType=VARCHAR},
            #{item.userId,jdbcType=VARCHAR},#{item.conductorId,jdbcType=VARCHAR}
        FROM DUAL
        </foreach>    
    </insert>

转载于:https://my.oschina.net/u/2356392/blog/785690

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值