程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> System.Data.OracleClient調用帶blob等大字段類型參數的存儲過程

System.Data.OracleClient調用帶blob等大字段類型參數的存儲過程

編輯:C#入門知識

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();
            } 

    

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved