ORA-01461 when Mybatis batch save Clob type: can bind a LONG value only for insert into a LONG column error Solution

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/Weixiaohuai/article/details/89682538

I. Introduction

In a recent project, we encountered a rather strange problem is that when I use Mybatis batch save Clob long text when an error can bind a LONG value only for insert into a LONG column, probably means "to bind only to insert LONG LONG column values ​​"even more surprising is that this error is only encountered in deploying to the test environment, this problem did not arise in the development environment, properly preserved, even the two environments are the same within the network database, when we had suspected Clob is not too long due, but normally saved without problems in the development environment, we gave up this conjecture. An error log is as follows:

Then a wave of your mother, saw some say is the problem Mybatis bulk preservation methods, as follows:

<insert id="insertPOBatch" parameterType="java.util.List">
	    insert into ZHXG_ZHCP_HJDFXQB(PKID,XSID,CPHJID,RWID,CPXQXX)
	        (
	            <foreach collection="list" item="row" index="index" separator="union all">
	                (select 
						#{row.pkid,jdbcType=VARCHAR},
						#{row.xsid,jdbcType=VARCHAR},
						#{row.cphjid,jdbcType=VARCHAR},
						#{row.rwid,jdbcType=VARCHAR},
						#{row.cpxqxx,jdbcType=CLOB}
	                   from dual)
	            </foreach> 
	        )
	</insert>

The above code, cpxqxx field is Clob type, it is possible to say that a large part of the problem is found in the data from the dual when taken in will Clob object field into a Long, so there can bind a LONG value only for insert into a LONG column this error.

 

Second, the solution

For the solution, we can use begin..end (personal feeling like the use of stored procedures), but this is another way for Oracle Mybatis batch saved, as follows:

	<!-- 此处批量插入暂时解决ORA-01461: can bind a LONG value only for insert into a LONG column问题 -->
	<insert id="insertPOBatch" parameterType="java.util.List">
        begin
	    <foreach collection="list" item="row" index="index" separator=";">
	       insert into ZHXG_ZHCP_HJDFXQB(PKID,XSID,CPHJID,RWID,CPXQXX)
	       values( #{row.pkid,jdbcType=VARCHAR},
                        #{row.xsid,jdbcType=VARCHAR},
                        #{row.cphjid,jdbcType=VARCHAR},
                        #{row.rwid,jdbcType=VARCHAR},
                        #{row.cpxqxx,jdbcType=CLOB}
                        )
	    </foreach> 
	    ;end;
	</insert>

Remember, ; End; semicolon before and can not forget. Try holding the mentality, the results actually succeeded, hereby record it in case you encounter back again, hoping to encounter the same problems of small partners, provide some solution ideas and methods.

 

Guess you like

Origin blog.csdn.net/Weixiaohuai/article/details/89682538