"ORA-00933: SQL command not properly ended" 使用 Oracle.ManagedDataAccess

"ORA-00933: SQL command not properly ended" using Oracle.ManagedDataAccess

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

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

我的查询:(如果使用 SQL Developer,returns 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 ;

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
        }
    }
}

但是在 "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

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

如果您有 select 语句,则必须删除“;”在查询结束时。 对于带有 "begin end" 块的 SQL 语句,您已删除末尾的“/”(此处需要“;”)