mybatis oracle mysql 批量插入
- - Oracle - 数据库 - ITeye博客一、oracle的批量插入方式. 二、mysql的批量插入方式. ORA-00918:未明确定义列. 如果不设置列名,那么#{item.senderPhone}的值就是默认列名,那么就有很多概率会产生列名重复,而产生异常. (两个列的值完全可能一样). #{item.receiveTime} 值为null时,必须指定转换类型.
insert into db(id, zgbh, shbzh) select '1', '2', '3' from dual union all select '2', '3', '4' from dual union all select '3', '4', '5' from dual union all select '4', '5', '6' from dual union all select '5', '6', '7' from dual
<insert id="insertMoSmsList" parameterType="com.xxx.XxxBean"> INSERT INTO TBL_xxx_DETAIL ( id, zgbh, shbzh, ReceiveTime ) SELECT SEQ_xxx_DETAIL.NEXTVAL, A.* FROM( <foreach collection="list" item="item" index="index" separator="UNION ALL"> <![CDATA[ SELECT #{item.id, jdbcType=INTEGER} AS id, #{item.zgbh, jdbcType=VARCHAR} AS zgbh, #{item.shbzh, jdbcType=VARCHAR} AS shbzh, TO_DATE(#{item.receiveTime, jdbcType=DATE},'yyyy-mm-dd hh24:mi:ss') AS ReceiveTime FROM dual ]]> </foreach> ) A </insert>
INSERT INTO MyTable(ID,NAME) VALUES (7,'003'),(8,'004'),(9,'005')
<insert id="insertBatch" > insert into student ( NAME,SEX,ADDRESS,TELEPHONE,TID) values <foreach collection="list" item="item" index="index" open="(" separator="," close=")"> #{item.name}, #{item.sex}, #{item.address}, #{item.telephone}, #{item.tId} </foreach> </insert>
#{item.receiveTime, jdbcType=DATE} AS ReceiveTime,
TO_DATE(#{item.receiveTime, jdbcType=DATE},'yyyy-mm-dd hh24:mi:ss') AS ReceiveTime,