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.