4

我得到了我只能描述为来自 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 ;

运行它的 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 模块正在向命令添加一些东西。

4

1 回答 1

8

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

于 2019-04-11T07:42:39.063 回答