Method of using string concatenation to insert into a CLOB field in "736c677c4" MyBatis

Source: Internet
Author: User
When inserting or updating the CLOB field on the Oracle database, the INSERT into and UPDATE statements are directly spliced, and a
ora-01704: String file too long

The exception. That's because Oracle's implicit conversion mechanism is that Oracle converts strings to VARCHAR2 types by default, and this string has a length greater than 4000, so a ora-01704 error is reported. To put it more generally, the characters between the two single quotes cannot be more than 4000, but I have to use single quotes to draw them because of business requirements. So I searched a lot of methods from the Internet, which was solved by the for Update method. But MyBatis does not know how to get resultset, so this method can only be dropped. Later saw the use of pl/sql on the Internet, I would like to try the direct use in the MyBatis can run, the results of a test found incredibly can. ...... Moved...... Tears running. The implementation methods are as follows:

Update the large segment individually
    private void Updateclobfields (String tablename,string dataid,list<map> FieldList, Ravforminstancemapper mapper) {for
        (Map field:fieldlist) {
            stringbuffer sb=new stringbuffer ();
            SB. Append ("DECLARE")
                    . Append ("   clobvalue clob;")
                    . Append ("BEGIN")
                    . Append ("   clobvalue: = '" +field.get ("value") + "';")
                    . Append ("   UPDATE" +tablename+ "t SET T." +field.get ("column") + "= Clobvalue WHERE t.id= '" +dataid+ "';")
                    . Append ("   COMMIT;")
                    . Append ("END;");

            Mapper.updateinst (Sb.tostring ());
        }
    

The Mapper.updateinst code is:

@Update ("${sql}") Public
    void Updateinst (@Param (value = "SQL") String SQL);


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.