您的位置:首页 > 数据库 > Oracle

mybatis批量插入记录到Oracle

2016-11-10 00:00 288 查看
序列为主键:

<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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐