CHAR(1) 字段中出现 ORA-12899 错误,但我只发送“C”
我的 Oracle 数据库返回错误:
ORA-12899 - 列的值太大 TIT.ESTADO_CIVIL(实际:2,最大: 1)
但我非常确定发送的值是唯一的字符“C”。
任何人都知道为什么会发生这种情况?
(我使用 C# 和 ODP.NET)
My Oracle database returns the error:
ORA-12899 - Value too large for column
TIT.ESTADO_CIVIL (actual: 2, maximum:
1)
But I'm very sure that the sended value is an unique char 'C'.
Anyone knows why this is happening?
(I'm using C# with ODP.NET)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有几种方法可以解决这个问题。最好的解决方案是修复数据库,使其使用字符语义。
您需要确保它能解决您的问题。修改您的表以使用字符语义并查看它是否删除了 ORA-12899 异常。
该文档有很多有关全球化和字符集的有用信息。您没有说明您正在使用哪个版本的数据库,因此这里有一个 有关长度语义的 9i 文档。
There are a couple of ways of dealing with this. The best solution would be to fix the database so it uses character semantics.
As this has major ramifications you need to be sure that it solves your problem. Modify your table to use character semantics and see whether it removes the ORA-12899 exceptions.
The documentation has a lot of helpful information on globalization and character sets. You don't say which version of the database you're using, so here's a link to the 9i docs on Length Semantics.
根据已接受的答案,在数据库级别进行修复似乎是最好的主意 - 因为它可以避免任何令人惊讶的行为。
但是,如果您不想在数据库级别修复(或无法访问),有两种方法可以帮助我实现此目的。我不确定第二个,但想分享它,以防有人发现它有用/可以解释它。
我的问题
char(1字节)
类型的输入参数,该参数用于设置char(1字节)
的值> 列我正在使用
System.Data.OracleClient.OracleCommand
这会遇到原始发布者提到的
值对于列来说太大
错误。解决方案 1
设置值后手动覆盖
OracleType
:解决方案 2
稍微更狡猾 - 只需使用一个字符串(我不明白为什么这是有效的,所以要小心依赖它):
Fixing at the database level seems like the best idea, as per the accepted answer - as it avoids any surprising behaviour.
However, if you don't want to fix (or can't access) at the database level, two ways worked for me to get this working. I'm not sure about the second one, but wanted to share it in case someone found it useful / could explain it.
My issue
char (1 byte)
, which is used to set the value of achar (1 byte)
columnI'm using
System.Data.OracleClient.OracleCommand
This hits the
value too large for column
error that the original poster mentions.Solution 1
Override the
OracleType
by hand after setting the value:Solution 2
Slightly more dodgy - just use a string (I don't understand why this works, so would be wary of relying on it):