C ++ reads and writes data from Oracle-Clob objects. Pay attention to the data encoding length.

Source: Internet
Author: User

[Cpp]

<Strong> c ++ reads and writes Clob objects. Pay attention to the data encoding length.
</Strong>
Read
// P_rs is resultset
If (p_rs-> next ())
{
Clob clob = p_rs-> getClob (4 );
If (! Clob. isNull ())
{
// Clob. setCharSetForm (OCCI_SQLCS_IMPLICIT); // The local encoding format seems to be incorrect.
Clob. setCharSetId ("UTF8"); // The database is stored in UTF-8
 
Unsigned int cloblen = clob. length ();
If (cloblen> 0)
{
Clob. open (OCCI_LOB_READONLY );
// UTF-8 must be multiplied by 3. Otherwise, only 1/3 of the actual data can be obtained.
Clob. read (cloblen * 3, (unsigned char *) msg_content, cloblen * 3, 1 );
Clob. close ();
}
}
}
Write
It should be written in varchar. There is no problem. Supports common SQL statements.
However, SQL statements have a limited length in oracle, so when the data is particularly long, you may need to consider using the Clob and write methods.
Author: RunBoying

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.