ORA-01461: Can only assign values to LONG values inserted into LONG Columns

Source: Internet
Author: User

Recently, when inserting data, I encountered the BUG of "ORA-01461: Can only assign values to the LOGN values of the inserted LOGN columns ".
 
The data type in oracle is varchar2 (4000 byte). The inserted data cannot exceed 4000.
 
Changes to varchar2 (4000 char), LONG, CLOB, and other types cannot be solved.
 
Google, most of the solutions on the Internet are to change the driver or change the database type. They have tried and are not valid.
 
I found that the length of the inserted data is about 1400, while that of oracle is inserting [1000 ~ 2000] between the data will be reported ORA-01461 error, less than 1000, or (2000 ~ 4000. The following operations are performed to solve the problem:

Java code
String content =...; // data to be inserted
Int len = content. getBytes (). length;
If (len> = 1000 & len <= 2000)
Content = StringUtils. rightPad (content, 2002 );
 
Note: To use StringUtils, You need to import the commons-lang package. rightPad () indicates filling spaces on the right.

Java code
StringUtils. rightPad (null, *) = null
StringUtils. rightPad ("", 3) = ""
StringUtils. rightPad ("bat", 3) = "bat"
StringUtils. rightPad ("bat", 5) = "bat"
StringUtils. rightPad ("bat", 1) = "bat"
StringUtils. rightPad ("bat",-1) = "bat"

Author "three lessons"
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.