报错
### Cause: java.sql.SQLException: ORA-01461: 仅能绑定要插入 LONG 列的 LONG 值
; uncategorized SQLException; SQL state [72000]; error code [1461]; ORA-01461: 仅能绑定要插入 LONG 列的 LONG 值
; nested exception is java.sql.SQLException: ORA-01461: 仅能绑定要插入 LONG 列的 LONG 值
Mybatis
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.test.OracleTableMapper">
<resultMap id="BaseResultMap" type="com.test.OracleTable">
<result column="id" jdbcType="BIGINT" property="id"/>
<result column="code" jdbcType="VARCHAR" property="code"/>
<result column="data" jdbcType="CLOB" property="data"/>
</resultMap>
<insert id="batchInsert" parameterType="map">
insert into oracle_table
(id, code, data)
select id, code, data from (
<foreach collection="list" item="item" separator=" union all ">
select #{item.id,jdbcType=BIGINT} as ID, #{item.code,jdbcType=VARCHAR} as CODE, #{item.data,jdbcType=CLOB}
as DATA
from dual
</foreach>
)
</insert>
</mapper>
原因是:当前表有Clob类型字段,在clob字段数据稍微大一点的时候,在当前的select ... dual 因为dual的原因,clob存储数据的时候不能正确获取
解决方式:使用begin end 方式进行批量插入
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.test.OracleTableMapper">
<resultMap id="BaseResultMap" type="com.test.OracleTable">
<result column="id" jdbcType="BIGINT" property="id"/>
<result column="code" jdbcType="VARCHAR" property="code"/>
<result column="data" jdbcType="CLOB" property="data"/>
</resultMap>
<insert id="batchInsert" parameterType="map">
begin
<foreach collection="list" item="item" separator=" ; ">
insert into oracle_table (id, code, data)
values
(
#{item.id,jdbcType=BIGINT}, #{item.code,jdbcType=VARCHAR}, #{item.data,jdbcType=CLOB}
)
</foreach>
;end;
</insert>
</mapper>