我得到的东西我只能描述为来自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
}
}
}
但在线上"使用(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提交的,我在服务器上执行时会得到可预期的存储过程相关错误,而是得到错误&#34; ORA-06550 PLS-00103:遇到符号&#34;,& #34;当期待以下之一时:&#34; ...让我觉得Oracle.ManagedDataAccess模块正在为命令添加一些内容。
答案 0 :(得分:0)
如果具有选择语句,则必须删除“;”在查询末尾。 对于带有“开始结尾”块的SQL语句,您已经在结尾处删除了“ /”(这里需要“;”)