Oracle clob field too long save error how to fix?

Source: Internet
Author: User
Tags oracleconnection
This problem occurs because the concatenation of SQL statements is too long to cause,

In general, Oracle SQL execution statements, English can not exceed 4000 characters, Chinese can not exceed 2000 characters, so once the content of the Clob field is more, there will be splicing of SQL

is too long to cause the problem to occur.

The simple workaround is to use a parameterized query to execute the SQL statement, the sample code is as follows

OracleConnection Con = new System.Data.OracleClient.OracleConnection (CONNECTSTR);  try {decimal MsgId =; 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.