C # An error occurred while saving the Oracle Clob field too long,

Source: Internet
Author: User
Tags oracleconnection

C # An error occurred while saving the Oracle Clob field too long,

This problem occurs mainly because the concatenated SQL statement is too long,

Generally, SQL statements executed in Oracle cannot exceed 4000 characters in English and 2000 characters in Chinese. Therefore, once the Clob field contains a large amount of content, a spliced SQL statement will appear.

Is too long, leading to problems.

A simple solution is to use parameterized queries to execute SQL statements. The sample code is as follows:

OracleConnection Con = new System. Data. OracleClient. OracleConnection (connectStr );
Try
{

Decimal MsgId = 20;
String InsertSql = @ "insert into MSG
(ID, TITLE, CONTENT, SORT, TIME, AUTHOR, GROUP)
Values
(: ID,
: TITLE,
: CONTENT,
: SORT,
: TIME,
: AUTHOR,
: GROUP )";

Con. Open ();
OracleCommand cmd = new OracleCommand (InsertSql, Con );
OracleParameter TITLE = new OracleParameter ("TITLE", OracleType. NVarChar );
OracleParameter CONTENT = new OracleParameter ("CONTENT", OracleType. Clob );
OracleParameter GID = new OracleParameter ("GID", OracleType. NVarChar );
OracleParameter SORT = new OracleParameter ("SORT", OracleType. Number );
OracleParameter TIME = new OracleParameter ("TIME", OracleType. DateTime );
OracleParameter AUTHOR = new OracleParameter ("AUTHOR", OracleType. NVarChar );
OracleParameter GROUP = new OracleParameter ("GROUP", OracleType. NVarChar );
TITLE. Value = Model. MsgTitle;
CONTENT. Value = Model. MsgContent;
ID. Value = Guid. NewGuid (). ToString ();
SORT. Value = MsgId;
TIME. Value = DateTime. Now;
AUTHOR. Value = Model. MsgAuthor;
GROUP. Value = Model. GroupId;
Cmd. Parameters. Add (MSGTITLE );
Cmd. Parameters. Add (MSGCONTENT );
Cmd. Parameters. Add (MSGID );
Cmd. Parameters. Add (MSGSORT );
Cmd. Parameters. Add (MSGTIME );
Cmd. Parameters. Add (MSGAUTHOR );
Cmd. Parameters. Add (MGSGROUP );
Cmd. ExecuteNonQuery ();
Con. Close ();

}
Catch (Exception ex)
{

}

Related Article

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.