有些是测试用的数据,不过我觉得功能上基本上是实现了。 顺便也附上单独插入CLOB或是BLOB的方法。我的也是在上面稍加改造弄出来的。
能同时插入CLOB和BLOB的
1/**//// <summary>
2 /// 同时写CLOB和BLOB
3 /// </summary>
4 /// <param name="bt">BLOB字段存的值</param>
5 /// <param name="clobbt">CLOB字段存的值</param>
6 /// <returns></returns>
7 private bool InsertBlobOrClob(byte[] bt,byte[] clobbt)
8 {
9 OracleConnection connection = new OracleConnection(ConStr);
10 connection.Open();
11 OracleTransaction transaction = connection.BeginTransaction();
12 OracleCommand command = connection.CreateCommand();
13 command.Transaction = transaction;
14 command.CommandText = "declare xx blob;yy clob; begin dbms_lob.createtemporary(xx, false, 0);dbms_lob.createtemporary(yy, false, 0); :tempblob := xx;:tempclob := yy; end;";
15 command.Parameters.Add(new OracleParameter("tempblob", OracleType.Blob)).Direction = ParameterDirection.Output;
16 command.Parameters.Add(new OracleParameter("tempclob", OracleType.Clob)).Direction = ParameterDirection.Output;
17 command.ExecuteNonQuery();
18
19 OracleLob tempLob = (OracleLob)command.Parameters[0].Value;
20 byte[] tempbuff = bt;
21 tempLob.BeginBatch(OracleLobOpenMode.ReadWrite);
22 tempLob.Write(tempbuff,0,tempbuff.Length);
23 tempLob.EndBatch();
24 OracleLob tempLob2 = (OracleLob)command.Parameters[1].Value;
25 byte[] tempbuff2 = clobbt;
26 tempLob2.BeginBatch(OracleLobOpenMode.ReadWrite);
27 tempLob2.Write(tempbuff2,0,tempbuff2.Length);
28 tempLob2.EndBatch();
29 command.Parameters.Clear();
30 command.CommandText = "insert into BLOBCLOB (案件编号,正文,内容) values ('caseno',:ImportCoc,:ImportDoc)";
31 command.CommandType = CommandType.Text;
32
33 command.Parameters.Add(new OracleParameter("ImportDoc", OracleType.Blob)).Value = tempLob;
34 command.Parameters.Add(new OracleParameter("ImportCoc", OracleType.Clob)).Value = tempLob2;
35 int num=command.ExecuteNonQuery();
36 transaction.Commit();
37 connection.Close();
38 return (num>=1);
39 }
1/**//// <summary>
2 /// 同时写CLOB和BLOB
3 /// </summary>
4 /// <param name="bt">BLOB字段存的值</param>
5 /// <param name="clobbt">CLOB字段存的值</param>
6 /// <returns></returns>
7 private bool InsertBlobOrClob(byte[] bt,byte[] clobbt)
8 {
9 OracleConnection connection = new OracleConnection(ConStr);
10 connection.Open();
11 OracleTransaction transaction = connection.BeginTransaction();
12 OracleCommand command = connection.CreateCommand();
13 command.Transaction = transaction;
14 command.CommandText = "declare xx blob;yy clob; begin dbms_lob.createtemporary(xx, false, 0);dbms_lob.createtemporary(yy, false, 0); :tempblob := xx;:tempclob := yy; end;";
15 command.Parameters.Add(new OracleParameter("tempblob", OracleType.Blob)).Direction = ParameterDirection.Output;
16 command.Parameters.Add(new OracleParameter("tempclob", OracleType.Clob)).Direction = ParameterDirection.Output;
17 command.ExecuteNonQuery();
18
19 OracleLob tempLob = (OracleLob)command.Parameters[0].Value;
20 byte[] tempbuff = bt;
21 tempLob.BeginBatch(OracleLobOpenMode.ReadWrite);
22 tempLob.Write(tempbuff,0,tempbuff.Length);
23 tempLob.EndBatch();
24 OracleLob tempLob2 = (OracleLob)command.Parameters[1].Value;
25 byte[] tempbuff2 = clobbt;
26 tempLob2.BeginBatch(OracleLobOpenMode.ReadWrite);
27 tempLob2.Write(tempbuff2,0,tempbuff2.Length);
28 tempLob2.EndBatch();
29 command.Parameters.Clear();
30 command.CommandText = "insert into BLOBCLOB (案件编号,正文,内容) values ('caseno',:ImportCoc,:ImportDoc)";
31 command.CommandType = CommandType.Text;
32
33 command.Parameters.Add(new OracleParameter("ImportDoc", OracleType.Blob)).Value = tempLob;
34 command.Parameters.Add(new OracleParameter("ImportCoc", OracleType.Clob)).Value = tempLob2;
35 int num=command.ExecuteNonQuery();
36 transaction.Commit();
37 connection.Close();
38 return (num>=1);
39 }
单独插入的
单独插入的
1OracleConnection connection = new OracleConnection("server=MyServer; integrated security=yes;");
2connection.Open();
3OracleTransaction transaction = connection.BeginTransaction();
4OracleCommand command = connection.CreateCommand();
5command.Transaction = transaction;
6command.CommandText = "declare xx blob; begin dbms_lob.createtemporary(xx, false, 0); :tempblob := xx; end;";
7command.Parameters.Add(new OracleParameter("tempblob", OracleType.Blob)).Direction = ParameterDirection.Output;
8command.ExecuteNonQuery();
9OracleLob tempLob = (OracleLob)command.Parameters[0].Value;
10byte[] tempbuff = new byte[10000];
11tempLob.BeginBatch(OracleLobOpenMode.ReadWrite);
12tempLob.Write(tempbuff,0,tempbuff.Length);
13tempLob.EndBatch();
14command.Parameters.Clear();
15command.CommandText = "MyTable.MyProc";
16command.CommandType = CommandType.StoredProcedure;
17command.Parameters.Add(new OracleParameter("ImportDoc", OracleType.Blob)).Value = tempLob;
18command.ExecuteNonQuery();
19transaction.Commit();
1OracleConnection connection = new OracleConnection("server=MyServer; integrated security=yes;");
2connection.Open();
3OracleTransaction transaction = connection.BeginTransaction();
4OracleCommand command = connection.CreateCommand();
5command.Transaction = transaction;
6command.CommandText = "declare xx blob; begin dbms_lob.createtemporary(xx, false, 0); :tempblob := xx; end;";
7command.Parameters.Add(new OracleParameter("tempblob", OracleType.Blob)).Direction = ParameterDirection.Output;
8command.ExecuteNonQuery();
9OracleLob tempLob = (OracleLob)command.Parameters[0].Value;
10byte[] tempbuff = new byte[10000];
11tempLob.BeginBatch(OracleLobOpenMode.ReadWrite);
12tempLob.Write(tempbuff,0,tempbuff.Length);
13tempLob.EndBatch();
14command.Parameters.Clear();
15command.CommandText = "MyTable.MyProc";
16command.CommandType = CommandType.StoredProcedure;
17command.Parameters.Add(new OracleParameter("ImportDoc", OracleType.Blob)).Value = tempLob;
18command.ExecuteNonQuery();
19transaction.Commit();
给自己做个记录。