System.Data.OracleClient在插入大字段類型的時候有32K大小限制,據網絡收集的一些方法,整理了一下如下(微軟企業庫示例):
必須在獲取臨時 LOB 之前開始事務。否則,OracleDataReader 將不能獲取後面的數據。
還可以通過調用 DBMS_LOB.CREATETEMPORARY 系統存儲過程並綁定 LOB 輸出參數打開 Oracle 中的臨時 LOB。在客戶端,臨時 LOB 的行為很像基於表的 LOB。例如,要更新臨時 LOB,它必須包含在事務中。
OracleConnection conn = Db.CreateConnection() as OracleConnection;
conn.Open();
OracleTransaction trans = conn.BeginTransaction() as OracleTransaction;
OracleCommand cmd = Db.DbProviderFactory.CreateCommand() as OracleCommand;
try
{
cmd.Transaction = trans;
cmd.Connection = conn;
cmd.CommandText = "GetTempBlob";
//存儲過程:GetTempBlob
//"declare dpBlob blob; begin dbms_lob.createtemporary(dpBlob, false, 0); :tempblob := dpBlob; end;";
//
cmd.Parameters.Add(new OracleParameter("tmpBlob", OracleType.Blob)).Direction = ParameterDirection.Output;
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
OracleLob tmpBlob = (OracleLob)cmd.Parameters[0].Value;
tmpBlob.BeginBatch(OracleLobOpenMode.ReadWrite);
tmpBlob.Write(bytNR, 0, bytNR.Length);
tmpBlob.EndBatch();
//執行插入存儲過程
cmd.Parameters.Clear();
cmd.CommandType = CommandType.StoredProcedure;
//cmd.Transaction = trans;
cmd.CommandText = "pkg_ManoeuvreScheme.Pro_SaveManoeuvreScheme";
Db.AddInParameter(cmd, "v_guid", DbType.String, "1");
Db.AddInParameter(cmd, "v_yxfamc", DbType.String, strYXFAMC);
Db.AddInParameter(cmd, "v_dy", DbType.String, strDY);
Db.AddInParameter(cmd, "v_bxsj", DbType.DateTime, dtBXSJ);
Db.AddInParameter(cmd, "v_yxfanr", DbType.String, strYXFANR);
Db.AddInParameter(cmd, "v_pj", DbType.String, strPJ);
Db.AddInParameter(cmd, "v_bz", DbType.String, strBZ);
Db.AddInParameter(cmd, "v_wdmc", DbType.String, strWDMC);
Db.AddParameter(cmd, "v_nr", OracleType.Blob, bytNR.Length,
ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, tmpBlob);
int ret = cmd.ExecuteNonQuery();
trans.Commit();
return ret;
}
catch (Exception ex)
{
trans.Rollback();
Logger.Error(ex);
throw ex;
}
finally
{
conn.Close();
}