在尝试使用最新的 ODP.NET 托管驱动程序查询 Oracle 数据库时,我正在尝试参数化 ROWNUM。
SQL 查询是“...WHERE ROWNUM <= :ROWSTOLOCK”
当我尝试添加 ROWNUM 作为参数时,如下所示:
dbCommand.Parameters.Add("ROWSTOLOCK", Oracle.ManagedDataAccess.Client.OracleDbType.Int64, 25 , ParameterDirection.Input);
我确实尝试执行查询
dbCommand.ExecuteNonQuery()
我得到一个例外:
“附加信息:ORA-01008:并非所有变量都绑定”
Row num 是一个数字,我们可以在之前的 Stack Overflow 帖子中看到:什么是 ROWNUM 的 OracleType
但是我找不到 Oracle.ManagedDataAccess.Client.OracleDbType.Number。我尝试在 Oracle.ManagedDataAccess.Client.OracleDbType 枚举中使用所有其他可用的数字类型。
我发现很难认为这是托管驱动程序的限制(数字类型不可用)。
代码片段:
string sql = "...WHERE ROWNUM & lt;= :ROWSTOLOCK";
string connectionString = "my connection string";
Oracle.ManagedDataAccess.Client.OracleConnection connectiont = new Oracle.ManagedDataAccess.Client.OracleConnection(connectionString);
Oracle.ManagedDataAccess.Client.OracleCommand dbCommand = new Oracle.ManagedDataAccess.Client.OracleCommand(sql, connectiont);
dbCommand.Parameters.Add("ROWSTOLOCK", Oracle.ManagedDataAccess.Client.OracleDbType.Decimal, 25, ParameterDirection.Input);
connectiont.Open();
int rowsAffected = dbCommand.ExecuteNonQuery();
完全例外:
ORA-01008: not all variables bound
Oracle Data Provider for .NET, Managed Driver
at OracleInternal.ServiceObjects.OracleCommandImpl.VerifyExecution(OracleConnectionImpl connectionImpl, Int32& cursorId, Boolean bThrowArrayBindRelatedErrors, OracleException& exceptionForArrayBindDML, Boolean& hasMoreRowsInDB, Boolean bFirstIterationDone)
at
OracleInternal.ServiceObjects.OracleCommandImpl.VerifyExecution(OracleConnectionImpl connectionImpl, Int32& cursorId, Boolean bThrowArrayBindRelatedErrors, OracleException& exceptionForArrayBindDML, Boolean bFirstIterationDone)
at OracleInternal.ServiceObjects.OracleCommandImpl.ExecuteNonQuery(String commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, Int32 longFetchSize, Int64 clientInitialLOBFS, OracleDependencyImpl orclDependencyImpl, Int64[]& scnFromExecution, OracleParameterCollection& bindByPositionParamColl, Boolean& bBindParamPresent, OracleException& exceptionForArrayBindDML, Boolean isFromEF)
at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery()
at QuickTest1.Program.Main(String[] args) in C:\Users\george\Documents\Visual Studio 2015\Projects\Program.cs:line 44
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
任何帮助都非常感谢。