“ORA-00933:SQL 命令未正确结束”使用 Oracle.ManagedDataAccess

use*_*141 3 c# oracle oracle-manageddataaccess

我得到了我只能描述为来自 nuget 的 oracle.ManagedDataAccess 包,似乎在我的查询末尾添加了字符。

我的最终目标是以 C# 命令参数的形式为下面的 SQL 提供绑定变量。

我的查询:(如果使用 SQL Developer 执行可以正常工作,返回 3 个字符串和一个日期时间)

with max_shift as (
  select max(shi.shift_id) shift_id
  from source_schema.site_instance ins
    join source_schema.tu_move_shifts shi on ins.instance_id = shi.instance_id
  where ins.instance_name = 'SiteOneSubsiteTwo' 
),
max_values as (
  select max(end_time) event_time 
  from max_shift ms
    join source_schema.events_extract ev on ev.move_shift_id = ms.shift_id
  where ev.site_code = 'SiteOne'

  union all 

  select max(destination_arrive_time) event_time
  from max_shift ms 
    join source_schema.movements_extract mov on mov.move_shift_id = ms.shift_id
  where mov.destination_site_code = 'SiteOne'
)
select 'Data Type One' as Type,
  'SiteOne' as Site,
  'Staging' as DataStore,
  min(event_time)
from max_values ;
Run Code Online (Sandbox Code Playgroud)

运行它的 C#:

using ( var connection = new Oracle.ManagedDataAccess.Client.OracleConnection(GetConnectionString(theconnectionstring.ToString())))
{
    using (var command = connection.CreateCommand())
    {
        connection.Open();
        var sourceQuery = connection.CreateCommand();
        sourceQuery.CommandTimeout = 0;
        sourceQuery.BindByName = true;
        //sourceQuery.CommandType = CommandType.StoredProcedure;
        sourceQuery.CommandType = CommandType.Text;
        sourceQuery.CommandText = GetSourceQuery(thequery);

        using (var reader = sourceQuery.ExecuteReader())
        {
            //stuff
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是在“using (var reader = sourceQuery.ExecuteReader())”行(如下所示为第 xxx 行)时,它会崩溃并显示以下内容:

Oracle.ManagedDataAccess.Client.OracleException (0x000003A5): ORA-00933: SQL command not properly ended
   at OracleInternal.ServiceObjects.OracleCommandImpl.VerifyExecution(OracleConnectionImpl connectionImpl, Int32& cursorId, Boolean bThrowArrayBindRelatedErrors, OracleException& exceptionForArrayBindDML, Boolean& hasMoreRowsInDB, Boolean bFirstIterationDone)
   at OracleInternal.ServiceObjects.OracleCommandImpl.ExecuteReader(String commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, OracleDataReaderImpl& rdrImpl, Int32 longFetchSize, Int64 clientInitialLOBFS, OracleDependencyImpl orclDependencyImpl, Int64[] scnForExecution, Int64[]& scnFromExecution, OracleParameterCollection& bindByPositionParamColl, Boolean& bBindParamPresent, Int64& internalInitialLOBFS, OracleException& exceptionForArrayBindDML, Boolean isDescribeOnly, Boolean isFromEF)
   at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior)
   at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteReader()
   at MonitoringService.MonitoringService.<ExecuteQueryAsync>d__10.MoveNext() in C:\_dev\Script_Consolidation\Monitoring\Monitoring\TSTLatencyMonitoringService.cs:line xxx
Run Code Online (Sandbox Code Playgroud)

如果这是作为 CommandType.StoredProcedure 提交的,则在服务器上执行时,我会收到与存储过程相关的预期错误,但会收到错误 "ORA-06550 PLS-00103: Encountered the symbol "," 当期望以下内容之一时:" 。 .. 让我觉得 Oracle.ManagedDataAccess 模块正在向命令添加一些东西。

Pin*_*ack 7

如果你有一个选择语句,你必须删除“;” 在查询结束时。对于带有“开始结束”块的 SQL 语句,您已删除末尾的“/”(此处您需要“;”)