oracle uint 数据类型的 ODP .NET 参数问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4098668/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 21:51:04  来源:igfitidea点击:

ODP .NET Parameter problem with uint datatype

c#oracleodp.net

提问by jreddy

After updating from the native .NET oracle data provider to Oracles ODP.NET, I've run into the following issue.

从本机 .NET oracle 数据提供程序更新到 Oracles ODP.NET 后,我遇到了以下问题。

I have a stored procedure that is part of a package, and it accepts 32 parameters, all IN but one, designated as an OUT parameter. Anyway, here is the issue I'm having. I have a date parameter passed in as a varchar2 and then 3 other parameters that are varchar2 as well. As for the rest, they are all NUMBER types.

我有一个存储过程,它是一个包的一部分,它接受 32 个参数,除了一个,全部是 IN,指定为一个 OUT 参数。无论如何,这就是我遇到的问题。我有一个日期参数作为 varchar2 传入,然后还有其他 3 个也是 varchar2 的参数。至于其余的,它们都是 NUMBER 类型。

In my .NET code all the values passed to the stored procedure are either string or int, with 4 exceptions. I have 4 items of data of type UInt32. The value they hold is too large for an int so uint was used.

在我的 .NET 代码中,传递给存储过程的所有值都是字符串或整数,但有 4 个例外。我有 4 项 UInt32 类型的数据。它们持有的值对于 int 来说太大了,所以使用了 uint。

Here is the problem. When we were using the native .NET oracle data provider, the parameter constructor includes a datatype of OracleType.Number, now the oracle parameter constructor has OracleDbType.Int32 and OracleDbType.Int64. The uint datatype didn't have a problem when set as the value of a parameter of datatype OracleType.Number, but now with the new client, I get different errors depending upon the datatypes I use.

这是问题所在。当我们使用原生的.NET oracle数据提供器时,参数构造函数包含一个数据类型OracleType.Number,现在oracle参数构造函数有OracleDbType.Int32和OracleDbType.Int64。将 uint 数据类型设置为数据类型 OracleType.Number 的参数值时没有问题,但现在使用新客户端时,根据我使用的数据类型,我收到不同的错误。

(By the way, the stored procedure runs fine when called with the values I'm passing in. These exceptions all occur within the ExecuteNonQuery statement of an Oracle Command object instance.)

(顺便说一下,当使用我传入的值调用时,存储过程运行良好。这些异常都发生在 Oracle Command 对象实例的 ExecuteNonQuery 语句中。)

I've changed the datatype holding my values as well as the datatype of the parameter, using the following combinations. Here are the results of each.

我使用以下组合更改了保存我的值的数据类型以及参数的数据类型。这是每个的结果。

.NET Datatype 'uint' ODP .NET Parameter data type 'OracleDbType.Int32'*System.OverflowException: Value was either too large or too small for an Int32. at System.Convert.ToInt32(UInt32 value) at System.UInt32.System.IConvertible.ToInt32(IFormatProvider provider) at System.Convert.ToInt32(Object value) at Oracle.DataAccess.Client.OracleParameter.PreBind_Int32() at Oracle.DataAccess.Client.OracleParameter.PreBind(OracleConnection conn, IntPtr errCtx, Int32 arraySize) at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery() at ScoutLoaderService.EventLoader.Load()*

.NET 数据类型 ' uint' ODP .NET 参数数据类型'OracleDbType.Int32'*System.OverflowException:值对于 Int32 来说太大或太小。在 System.Convert.ToInt32(UInt32 value) 在 System.UInt32.System.IConvertible.ToInt32(IFormatProvider provider) 在 System.Convert.ToInt32(Object value) 在 Oracle.DataAccess.Client.OracleParameter.PreBind_Int32() 在 Oracle.DataAccess .Client.OracleParameter.PreBind(OracleConnection conn, IntPtr errCtx, Int32 arraySize) 在 Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery() 在 ScoutLoaderService.EventLoader.Load()*

.NET Datatype 'uint' ODP .NET Parameter data type 'OracleDbType.Int64'Oracle.DataAccess.Client.OracleException ORA-06502: PL/SQL: numeric or value error: character to number conversion error ORA-06512: at line 1 at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtxpOpoSqlValCtx, Object src, String procedure, Boolean bCheck) at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, Boolean bCheck) at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery() at ScoutLoaderService.EventLoader.Load()*

.NET 数据类型 ' uint' ODP .NET 参数数据类型'OracleDbType.Int64' Oracle.DataAccess.Client.OracleException ORA-06502:PL/SQL:数字或值错误:字符到数字转换错误 ORA-06512:在第 1 行处Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtxpOpoSqlValCtx, Object src, String procedure, Boolean bCheck) 在 Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, procedure OracleConnection String , IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, Boolean bCheck) 在 Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery() 在 ScoutLoaderService.EventLoader.Load()*

.NET Datatype 'Int64' ODP .NET Parameter data type 'OracleDbType.Int64'Oracle.DataAccess.Client.OracleException ORA-06502: PL/SQL: numeric or value error: character to number conversion error ORA-06512: at line 1 at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtxpOpoSqlValCtx, Object src, String procedure, Boolean bCheck) at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, Boolean bCheck) at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery() at ScoutLoaderService.EventLoader.Load()*

.NET 数据类型 ' Int64' ODP .NET 参数数据类型'OracleDbType.Int64' Oracle.DataAccess.Client.OracleException ORA-06502:PL/SQL:数字或值错误:字符到数字转换错误 ORA-06512:在第 1 行处Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtxpOpoSqlValCtx, Object src, String procedure, Boolean bCheck) 在 Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, procedure OracleConnection String , IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, Boolean bCheck) 在 Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery() 在 ScoutLoaderService.EventLoader.Load()*

回答by jreddy

The problem it turns out had nothing to do with the data types. I used the Int64 in the Oracle Parameter and it worked, but only after setting the BindByName property on my Command object to true.

事实证明,问题与数据类型无关。我在 Oracle Parameter 中使用了 Int64 并且它起作用了,但只有在我的 Command 对象上的 BindByName 属性设置为 true 之后。

Apparently the default for the .NET System.Data.OracleClient provider 'BINDING BY NAME', whereas the default for Oracle.DataAccess is 'BIND BY POSITION'.

显然 .NET System.Data.OracleClient 提供程序的默认值是“BINDING BY NAME”,而 Oracle.DataAccess 的默认值是“BIND BY POSITION”。

It would have been nice if the Oracle Exception caught would have contained more information, like which parameter was throwing the exception. This may have helped me discover the issue sooner.

如果捕获的 Oracle 异常包含更多信息(例如哪个参数引发异常),那就太好了。这可能有助于我更快地发现问题。

回答by Harrison

I think that OracleDecimal is the way to go here check out Data Type Conversion; even herethey map int34 to BINARY_INTEGER.

我认为 OracleDecimal 是检查数据类型转换的方法;即使在这里,他们也将 int34 映射到 BINARY_INTEGER。

by the way, OracleDecimal is huge and you shouldn't run into any problems

顺便说一句,OracleDecimal 是巨大的,你不应该遇到任何问题

Here is another really good reference: OracleParameterClass. For return parameters the the OracleDbTypeExcan be very helpful.

这是另一个非常好的参考:OracleParameterClass。对于返回参数,OracleDbTypeEx可能非常有用。