Oracle inserts the CLOB field with over 4000 bytes

  • 2020-06-15 10:25:06
  • OfStack

Through the puzzle of sql statements to implement data into applications, we are likely to meet the condition of the large data to be inserted, for example, the number of bytes to be inserted in the oracle content, more than 4000 field if we through simple puzzle of sql statements to implement insert, apparently can be a problem, and in sql server without this restriction, in 26 w characters of individual tried sql statements in sql server2005, still can be inserted into the data, But inserting more than 4,000 characters into oracle will raise an exception.

The solutions to this problem are summarized as follows:
We can obtain the success by creating a separate OracleCommand to perform the specified insertion, here only introduces the insertion of clob type of data, blob is similar, here is not introduced, the following two methods, both verified:
Method 1: Use the component System.Data.OracleClient, which is simpler 1:

string conn = "Data Source= The 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 = " More than 4000 A supernormal string of characters "; 
cmd.Parameters.Add(op); 
cmd.ExecuteNonQuery(); 
Con.Close();

Method 2: Implemented using the component Oracle.DataAccess, which may be a little older, but still works:

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 = " More than 4000 A supernormal string of characters "; 
m_arrParamter.Insert(0, objParam); 

int nRet = m_objCmd.ExecuteNonQuery();

Of course, sql server can also add strings this way, but adding a base 2 file is the only way to add strings because you need to read the contents of the file's base 2 stream.

Related articles: