我从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“,”当预期以下之一时:“.
2条答案
按热度按时间ttygqcqt1#
如果你有一个select语句,你必须在查询的末尾删除“;”。对于一个带有“开始结束”块的SQL语句,你必须在末尾删除“/”(这里你需要“;”)
ijxebb2r2#
当在.NET Core 6应用程序中使用Entity Framework Core与Oracle时,我遇到了同样的问题。为了解决这个问题,我指定了Oracle版本
UseOracleSQLCompatibility("11")
这确保了使用Oracle 11g SQL语法而不是较新的12+。字符串