【问题标题】:ORA-12537 when invoking bulk Merge - Oracle.ManagedDataAccess.ClientORA-12537 调用批量合并 - Oracle.ManagedDataAccess.Client
【发布时间】:2014-04-17 00:39:37
【问题描述】:

我正在尝试使用 ArrayBindCount 插入/更新许多记录。

它适用于 1 和 2 条记录,但如果我尝试插入 3 或更多,我会得到 ORA-12537 异常。

我正在使用 Oracle.ManagedDataAccess.dll 版本 4.121.1.0。 我也试过 OracleXE 11gOracle Standard 11g

这是我正在使用的 sql:

MERGE INTO tb_medidor_ene t1 
USING (select :pId cd_medidor, :pDate dt_hr_instante, :pValor vl_eneat_del from dual) t2 ON (t1.cd_medidor = t2.cd_medidor and t1.dt_hr_instante = t2.dt_hr_instante) 
WHEN MATCHED THEN update set t1.vl_eneat_del = t2.vl_eneat_del, dt_hr_insercao = :pInsertDate 
WHEN NOT MATCHED THEN INSERT (t1.cd_medidor, t1.dt_hr_insercao, t1.dt_hr_instante, t1.vl_eneat_del) 
VALUES (t2.cd_medidor, :pInsertDate, t2.dt_hr_instante, t2.vl_eneat_del)

还有这个(简化的)代码:

    int num = 3;
    int index;
    var ids = new int[num];
    var insertDates = new DateTime[num];
    var dates = new DateTime[num];
    var values = new double[num];

    for (index = 0; index < num; index++) {
        ids[index] = 1;
        insertDates[index] = DateTime.Now;
        dates[index] = DateTime.Today.AddMinutes(index * 5);
        values[index] = index;
    }
    using (var conn = new OracleConnection(Program.ConnString)) {
        conn.Open();
        using (var command = conn.CreateCommand()) {
            command.ArrayBindCount = num;
            command.CommandText = sql;
            command.BindByName = true;
            command.Parameters.Add(new OracleParameter("pId", ids));
            command.Parameters.Add(new OracleParameter("pInsertDate", insertDates));
            command.Parameters.Add(new OracleParameter("pDate", dates));
            command.Parameters.Add(new OracleParameter("pValor", values));
            command.ExecuteNonQuery();
        }
    }

“Oracle.ManagedDataAccess.dll 中发生了“Oracle.ManagedDataAccess.Client.OracleException”类型的未处理异常”

{"ORA-12537: Biblioteca de Rede: Fim do arquivo"}

堆栈跟踪:

在 Oracle.ManagedDataAccess.Client.OracleException.HandleError(OracleTraceLevel 级别,OracleTraceTag 标记,异常 ex) 在 OracleInternal.TTC.TTCExecuteSql.ReceiveExecuteResponse(Accessor[]& defineAccessors, Accessor[] bindAccessors, Boolean bHasReturningParams, SQLMetaData& sqlMetaData, SqlStatementType statementType, Int64 noOfRowsFetchedLastTime, Int32 noOfRowsToFetch, Int32& noOfRowsFetched, Int64& queryId, Int32 longFetchSize, Int33 scnFromExecution, Boolean& bAllPureInputBinds, DataUnmarshaller& dataUnmarshaller, MarshalBindParameterValueHelper& marshalBindParamsHelper, Boolean bDefineDone) 在 OracleInternal.ServiceObjects.OracleCommandImpl.ExecuteNonQuery(String commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, Int32 longFetchSize, Int32 lobPrefetchSize, OracleDependencyImpl orclDependencyImpl, Int64[]& scnFromExecution, OracleParameterCollection& bindByPositionParamColl, Boolean& bBindParamPresent, Boolean is 在 Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery() 在 c:\dev\way2\DataIn\OraclePlayground\OraclePlayground\Program.cs:line 114 中的 OraclePlayground.Program.Main(String[] args) 在 System.AppDomain._nExecuteAssembly(RuntimeAssembly 程序集,字符串 [] 参数) 在 System.AppDomain.ExecuteAssembly(字符串 assemblyFile,证据 assemblySecurity,String [] args) 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在 System.Threading.ThreadHelper.ThreadStart_Context(对象状态) 在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback 回调,对象状态,布尔值 preserveSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback 回调,对象状态,布尔值 preserveSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback 回调,对象状态) 在 System.Threading.ThreadHelper.ThreadStart()

【问题讨论】:

  • 我遇到了同样的问题,但我的限制是 4。从 5 条合并语句中我得到了同样的错误。你能解决这个问题吗?
  • @mosu 请看下面我的回答。
  • 谢谢 andrecarlucci 但这是我不想使用的解决方法。我改用批处理命令。

标签: c# oracle oracle11g bulkinsert odp.net


【解决方案1】:

对于有同样问题的人:

我最终创建了一个存储过程,它除了执行我试图直接执行的相同 SQL 之外什么都不做。

然后您可以批量调用该过程并且它工作正常。

到目前为止,在 Oracle 人员解决问题之前,这是唯一的方法。

【讨论】:

  • 另一种选择是只在 for 循环中执行 Merge 语句。我知道这不是批量操作,它会更慢,但至少它可以与 4.121.1.0 版本一起使用
【解决方案2】:

我遇到了类似的问题。合并项目导致 ORA-12537 错误。这很奇怪,因为它工作了一段时间,然后没有。我最终将其缩小为 CLOB 字段中的空值。如果 CLOB 只有一个值为空,它会起作用,但如果有多个,它会一直死掉。我通过将其更改为在 CLOB 中放置一个空格来解决它(即使使用 '' 也会导致错误)。浪费了一个空间,但至少错误消失了。

这对我来说似乎是一个错误。我在本地运行 Oracle 11.2.0.3.0 64 位。希望这会有所帮助...

【讨论】:

    猜你喜欢
    • 2017-06-15
    • 2016-11-26
    • 1970-01-01
    • 1970-01-01
    • 2015-07-03
    • 2017-01-23
    • 1970-01-01
    • 1970-01-01
    • 2021-12-15
    相关资源
    最近更新 更多