OracleConnection conn = new OracleConnection("server=MyServer; integrated security=yes;");
conn.Open();
//啓動一個事務
OracleTransaction tx = conn.BeginTransaction();
構造一個sql命令對象,並指定這個命令的事務對象
OracleCommand cmd = conn.CreateCommand();
cmd.Transaction = tx;
//這裏是關鍵,他定義了一個命令對象的t-sql語句,通過dmbs_lob來創建一個零時對象,這個對象的類型爲blob,並存放在變量xx中,然後將xx的值付給外傳參數tmpblob
cmd.CommandText = "declare xx blob; begin dbms_lob.createtemporary(xx, false, 0); :tempblob := xx; end;";
//構造外傳參數對象,並加入到命令對象的參數集合中
cmd.Parameters.Add(new OracleParameter("tempblob", OracleType.Blob)).Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
//構造OracleLob對象,他的值爲tmpblob外傳參數的值
OracleLob tempLob = (OracleLob)cmd.Parameters[0].Value;
//指定tempLob的訪問模式,並開始操作二進制數據
tempLob.BeginBatch(OracleLobOpenMode.ReadWrite);
//將二進制流byte數組集合寫入到tmpLob裏
tempLob.Write(tempbuff,0,tempbuff.Length);
tempLob.EndBatch();
cmd.Parameters.Clear();
cmd.CommandText = "myTable.myProc";
cmd.CommandType = CommandType.StoredProcedure;
//創建存儲過程的Blob參數,並指定Blob參數的值爲tempLob(表示服務器上大型對象二進制數據類型),並將Blob參數加入到command對象的參數集合裏
cmd.Parameters.Add(new OracleParameter("ImportDoc", OracleType.Blob)).Value = tempLob;
cmd.ExecuteNonQuery();
tx.Commit();