mybatis批量插入記錄到Oracle

序列爲主鍵:java

<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>ui

uuid爲主鍵:it

<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>io

相關文章
相關標籤/搜索