How Oracle inserts a CLOB field with a super 4000 byte

Source: Internet
Author: User
Tags oracleconnection

Recently in the system development need to want to insert more than 4000 bytes of Oracle database Clob field, on-line query for n long to find the following solution, it is retained for later investigation.

We can be successful by creating a separate OracleCommand for the specified insert, only the data that is inserted into the CLOB type, the blob is similar, this is not described here, the following two ways

In an application that implements data insertion through a group of SQL statements, we are likely to encounter situations where large data needs to be inserted, such as when we need to insert a field with more than 4000 bytes in Oracle, and if we implement the insert through a simple group SQL statement, there is a clear problem with the SQL There is no such restriction in the server, and a personal SQL statement that attempts a 26w character is executed in SQL server2005, and the data can still be inserted, but an exception is reported when inserting more than 4,000 characters into Oracle.

The following solution to this problem, do a summary:
We can be successful by creating a separate OracleCommand for the specified insert, only the data that is inserted into the CLOB type, the blob is similar, this is not described here, the following two methods are verified:
The first method: Using the component System.Data.OracleClient method to implement, relatively simple:

Copy CodeThe code is as follows:
String conn = "Data source= client Specifies the connection string; User Id=user; Password=mima ";
OracleConnection Con = new System.Data.OracleClient.OracleConnection (conn);
Con.open ();
String cmdtext = "INSERT into gwexpointlist (ID, name, content) VALUES (1, ' name ',: CLOB)";
OracleCommand cmd = new OracleCommand (Cmdtext, Con);
OracleParameter op = new OracleParameter ("Clob", Oracletype.clob);
Op. Value = "an extraordinary string exceeding 4000 characters";
Cmd. Parameters.Add (OP);
Cmd. ExecuteNonQuery ();
Con.close ();


The second method, implemented using the component Oracle.dataaccess method, may be slightly older, but still valid:

Copy CodeThe code is as follows:
IDbCommand m_objcmd = new OracleCommand ();
M_objcmd.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 = "an extraordinary string exceeding 4000 characters";
M_arrparamter.insert (0, Objparam);

int nret = M_objcmd.executenonquery ();


Of course, SQL Server can also use this method to add strings, but to add a binary file, it can only be added in this way, because it is necessary 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.