Home > Article > Backend Development > How to solve the problem of saving the Oracle Clob field that is too long?
The reason for this problem is mainly because the spliced SQL statement is too long.
Generally speaking, Oracle's SQL execution statement cannot exceed 4000 characters in English and 2000 characters in Chinese, so once Clob If there are many fields, the length of the spliced SQL
will be too long, which will lead to problems.
The simpler solution is to use parameterized query 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) { }
The above is the detailed content of How to solve the problem of saving the Oracle Clob field that is too long?. For more information, please follow other related articles on the PHP Chinese website!