Oracle.ManagedDataAccess.Client.OracleException - ORA-01722:无效的数字

时间:2014-11-27 09:36:34

标签: c# oracle oracle11g datacontext

我在.NET 4.5 C#,oracle 11g环境中工作。

当我使用datacontext从代码中调用SQL语句

时,我遇到了特殊的行为

我得到ORA-01722: invalid number

enter image description here

堆栈跟踪:

   at Corp.DataServices.ExecuteQueryHandler.HandleQueryException(Exception exception) in c:\dev\CCTech Main\Corp\Corp.Conveyancing.DataServices\FluentData.cs:line 4022
   at Corp.DataServices.ExecuteQueryHandler.ExecuteQuery(Boolean useReader, Action action) in c:\dev\CCTech Main\Corp\Corp.Conveyancing.DataServices\FluentData.cs:line 3993
   at Corp.DataServices.DbCommand.QueryMany[TEntity,TList](Action`2 customMapper) in c:\dev\CCTech Main\Corp\Corp.Conveyancing.DataServices\FluentData.cs:line 3857
   at Corp.DataServices.DbCommand.QueryMany[TEntity](Action`2 customMapper) in c:\dev\CCTech Main\Corp\Corp.Conveyancing.DataServices\FluentData.cs:line 3882
   at Corp.Dashboard.Controllers.HomeController.GetInstructionsJson(String id) in c:\dev\CCTech Main\Corp\Corp.Conveyancing.Dashboard\Controllers\HomeController.cs:line 65
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.ActionInvocation.InvokeSynchronousActionMethod()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass48.<InvokeActionMethodFilterAsynchronouslyRecursive>b__41()

现在到了特殊的部分 当我直接从PL / SQL执行完全相同的sql时,它的工作正常 enter image description here

发生了什么?声明中没有任何演员表。我必须在这里遗漏一些明显的东西。

1 个答案:

答案 0 :(得分:1)

您无法以这种方式传递参数。当你这样做时,它会将SQL呈现为:

WHERE productid IN ('1,2,3,4,5')

将尝试将值作为单个字符串强制转换为数字。相反,你可以:

  • 使用表值参数将值作为数组传递。我之前没有这样做但很确定它是可能的,例如How to use Array/Table Parameter to Oracle (ODP.NET 10g) via ADO.NET/C#?
  • 忘记使用参数并使用字符串连接。通常不是一个好主意(SQL注入等),但操作简单。要使用RegEx验证输入(并假设数字之间没有任何空格),您可以使用它来匹配输入(稍微修改@LIUFA的注释):^[0-9][\,0-9]*$