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)
{
}