mybatis批量插入clob,ORA-01461-僅能繫結要插入LONG列的LONG值
阿新 • • 發佈:2019-02-14
今天用MyBatis批量插入資料到Oracle中,其中有欄位的型別為Clob,出現錯誤:ORA-01461:僅能繫結要插入LONG列的LONG值
Xml中SQL語句如下:
<insert id="batchInsert" parameterType="java.util.List">
insert into tableName (ID, LAST_MODIFIED, content)
<foreach collection="list" item="item" index="index" close=")" open="(" separator="union" >
select #{item.id},to_date(#{item.lastModified},'YYYY-MM-DD HH24:MI:SS') ,#{item.content} from dual
</foreach>
</insert>
其中content欄位在資料庫中是Clob型別。
在網上查了很久,有可能問題是出現在當從dual中取資料時,會將clob物件的欄位轉為Long型
最後的解決方法用到了Begin和end語法:
<insert id="batchInsert" parameterType="java.util.List" >
begin
<foreach collection="list" item="item" index="index" separator=";">
insert into tableName(ID, LAST_MODIFIED, content)
values( #{item.id},to_date(#{item.lastModified},'YYYY-MM-DD HH24:MI:SS'),#{item.content})
</foreach>
;end;
</insert>
成功插入了多條包含Clob的資料