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.