How to solve the problem of saving the Oracle Clob field that is too long?

零下一度
Release: 2018-05-26 16:02:14
Original
3407 people have browsed it

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 parameterizedqueryto 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) { }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!