简体   繁体   English

这是Oracle ODP.NET中的错误吗?

[英]Is this a bug in the Oracle ODP.NET

I'm curious if this is a bug in the Oracle ODP.NET provider. 我很好奇这是否是Oracle ODP.NET提供程序中的错误。 I created a parameterized insert statement. 我创建了一个参数化的插入语句。 I named one of the parameters ':EMPNO' and when testing it gave it a value of '8000'. 我将参数之一命名为“:EMPNO”,并在测试时将其值设为“ 8000”。 In the database the EMPNO column was defined as varchar2(4 byte). 在数据库中,EMPNO列定义为varchar2(4字节)。 However, the insert gave an error message of 但是,该插入给出了一条错误消息

ORA-12899: value too large for column "HR"."HR_DEPARTURE"."EMPNO" (actual: 6, maximum: 4) ORA-12899:值对于列“ HR”。“ HR_DEPARTURE”。“ EMPNO”太大(实际:6,最大值:4)

Here is some code snipets: 这是一些代码片段:

"INSERT INTO HR.HR_DEPARTURE (EMPNO) ':EMPNO'"

I then add a parameter 然后我添加一个参数

new OracleParameter(":EMPNO", OracleDbType.Varchar2) {Value = empNo ?? Convert.DBNull}

Create a command and add the parameter (there were multiple parameters thus the array) 创建一个命令并添加参数(因此有多个参数,因此是数组)

DbCommand cmd = Connection.CreateCommand();
cmd.Parameters.AddRange(sqlParams.ToArray());

I did some research and considered things like encoding and the fact that Oracle defaults to bind by position (instead of BindByName). 我进行了一些研究,并考虑了编码等问题,以及Oracle默认使用位置绑定(而不是BindByName)这一事实。 However, none of these resolved the issue. 但是,这些方法都无法解决问题。 I then took a shot in the dark and changed the parameter name to ":EMPN" and got the following error message: 然后,我在黑暗中拍照,并将参数名称更改为“:EMPN”,并收到以下错误消息:

ORA-12899: value too large for column "HR"."HR_DEPARTURE"."EMPNO" (actual: 5, maximum: 4) ORA-12899:列“ HR”。“ HR_DEPARTURE”。“ EMPNO”的值太大(实际:5,最大值:4)

This clued me in to change the parameter name to ":EMP" at which time the query worked. 这促使我在查询工作时将参数名称更改为“:EMP”。 I find it very odd that the provider is enforcing the database column size on the parameter name in c#. 我发现提供者在c#中的参数名称上强制数据库列大小非常奇怪。 The database size should be an enforcement of the value ('8000' which I kept the same in all tests). 数据库大小应该是值的强制性(“ 8000”,我在所有测试中均保持相同)。

No; 没有; the problem is that your query makes no sense. 问题是您的查询没有意义。

':EMPNO' is a string with the literal value :EMPNO , which is five characters long. ':EMPNO'是字面值:EMPNO的字符串,其长度为五个字符。

To reference a parameter, don't write a string literal. 要引用参数,请不要编写字符串文字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM