How to insert a CLOB field of over 4000 bytes in Oracle

Source: Internet
Author: User
Tags oracleconnection
We can create a separate OracleCommand to insert the specified data. Here we only introduce the data of the clob type. blob is similar to this. Here we will not introduce it. The following two methods are described.

We can create a separate OracleCommand to insert the specified data. Here we only introduce the data of the clob type. blob is similar to this. Here we will not introduce it. The following two methods are described.

In an application that inserts data using SQL statements in a group, we may encounter the need to insert large data, for example, when we need to insert fields with more than 4000 bytes in oracle, if we use a simple grouping SQL statement to insert the fields, we will obviously encounter problems, this restriction is not imposed on SQL server. I tried to execute a-character SQL statement in SQL server and still can insert data, however, if you insert more than 4000 characters in oracle, an exception is reported.

The following is a summary of the solution to this problem:
You can create a separate OracleCommand to insert the specified data. Here, we only introduce the data of the clob type. blob is similar to this. We will not introduce it here, the following two methods have been verified:
Method 1: Use the System. Data. OracleClient component to implement it, which is simpler:
The Code is as follows:
String conn = "Data Source = connection string specified by the client; User ID = user; Password = mima ";
OracleConnection Con = new System. Data. OracleClient. OracleConnection (conn );
Con. Open ();
String jsontext = "insert into gwexpointlist (id, name, content) VALUES (1, 'name',: clob )";
OracleCommand cmd = new OracleCommand (plain text, Con );
OracleParameter op = new OracleParameter ("clob", OracleType. Clob );
Op. Value = "super-normal string with more than 4000 characters ";
Cmd. Parameters. Add (op );
Cmd. ExecuteNonQuery ();
Con. Close ();

Method 2: Use the Oracle. DataAccess component. The usage may be a little older, but it is still valid:
The Code is as follows:
IDbCommand m_objCmd = new OracleCommand ();
M_obj316.commandtext = "insert into gwexpointlist (id, name, content) VALUES (1, 'name',: clob )";
IDataParameterCollection m_arrParamter = m_objCmd.Parameters;
OracleClob clob = new OracleClob (OracleConnection) m_objConn );
OracleParameter objParam = new OracleParameter ('clob', OracleDbType. clob, Clob, ParameterDirection. Input );

ObjParam. Value = "super-normal string with more than 4000 characters ";
M_arrParamter.Insert (0, objParam );

Int nRet = m_obj).executenonquery ();

Of course, SQL server can also use this method to add strings. However, if you add a binary file, you can only use this method to add it because you need to read the binary stream content of the file.

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.