有些是测试用的数据,不过我觉得功能上基本上是实现了。 顺便也附上单独插入CLOB或是BLOB的方法。我的也是在上面稍加改造弄出来的。
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
能同时插入CLOB和BLOB的
1![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//// <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![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
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![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
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
}
单独插入的
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
单独插入的
1
OracleConnection connection = new OracleConnection("server=MyServer; integrated security=yes;");
2
connection.Open();
3
OracleTransaction transaction = connection.BeginTransaction();
4
OracleCommand command = connection.CreateCommand();
5
command.Transaction = transaction;
6
command.CommandText = "declare xx blob; begin dbms_lob.createtemporary(xx, false, 0); :tempblob := xx; end;";
7
command.Parameters.Add(new OracleParameter("tempblob", OracleType.Blob)).Direction = ParameterDirection.Output;
8
command.ExecuteNonQuery();
9
OracleLob tempLob = (OracleLob)command.Parameters[0].Value;
10
byte[] tempbuff = new byte[10000];
11
tempLob.BeginBatch(OracleLobOpenMode.ReadWrite);
12
tempLob.Write(tempbuff,0,tempbuff.Length);
13
tempLob.EndBatch();
14
command.Parameters.Clear();
15
command.CommandText = "MyTable.MyProc";
16
command.CommandType = CommandType.StoredProcedure;
17
command.Parameters.Add(new OracleParameter("ImportDoc", OracleType.Blob)).Value = tempLob;
18
command.ExecuteNonQuery();
19
transaction.Commit();
给自己做个记录。