Mybatis批量插入数据(Mysql / Oracle)
程序员文章站
2022-07-12 13:52:48
...
Mysql 的批量插入方式:
<insert id="insertDataByBatch">
insert into RECORD_IMFORMATION
(recordId,toUserId,roomName,fromUserId,entityType,
entityContent,url)
values
<foreach collection="records" item="record" separator="," >
(#{record.recordId},#{record.toUserId},#{record.roomName},
#{record.fromUserId},#{record.entityType},
#{record.entityContent},#{record.url})
</foreach>
</insert>
Oracle的批量插入方式:
<insert id="insertDataByBatch">
insert into RECORD_IMFORMATION
(recordId,toUserId,roomName,fromUserId,entityType,
entityContent,url)
SELECT A.* FROM (
<foreach collection="records" item="record" index="index" separator="UNION ALL" >
SELECT
#{record.recordId, jdbcType=VARCHAR} recordId,
#{record.toUserId, jdbcType=VARCHAR} toUserId,
#{record.roomName, jdbcType=VARCHAR} roomName,
#{record.fromUserId, jdbcType=VARCHAR} fromUserId,
#{record.entityType, jdbcType=VARCHAR} entityType,
#{record.entityContent, jdbcType=VARCHAR} entityContent,
#{record.url, jdbcType=VARCHAR} url
FROM dual
</foreach>
) A
</insert>
上一篇: mysql my.ini 配置文件
下一篇: vs2012属性管理器哪里找?