oracle ora-01406 使用 OCI 获取值时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1458881/
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 19:02:38  来源:igfitidea点击:

ora-01406 Error when fetching values using OCI

oracleoci

提问by Gayan

This occurs when fetching values which have a max length of 50, to a buffer which could only hold 30 chars.

当将最大长度为 50 的值提取到只能容纳 30 个字符的缓冲区时,会发生这种情况。

I've already looked up the error and found a possible solution, which is to expand the size of the buffer which the value is bound to.

我已经查找了错误并找到了一个可能的解决方案,即扩大该值绑定到的缓冲区的大小。

The problem is, this occurs only in some of our systems and not in others. Does the Oracle version have anything to do with this? If so, what is the version in which this error has been changed?

问题是,这只会发生在我们的某些系统中,而不会发生在其他系统中。oracle版本跟这个有关系吗?如果是这样,更改此错误的版本是什么?

The Oracle versions we use are 10.2.0.1 and 10.2.0.3

我们使用的Oracle版本是10.2.0.1和10.2.0.3

采纳答案by Gayan

The bug listed in the question has been fixed in 10.2.0.3 and The error is only given in Oracle versions prior to that. Edit: The same issue was seen in Oracle 10.2.0.4. We're still looking in to this

问题中列出的错误已在 10.2.0.3 中修复,并且该错误仅在之前的 Oracle 版本中出现。编辑:在 Oracle 10.2.0.4 中也出现了同样的问题。我们还在研究这个

Edit2: When defining cursors for CHAR/VARCHAR columns in OCI (we use a wrapper for this purpose), the size of the string which is bound to a column must be at least one greater than the maximum width of the column.

Edit2:在 OCI 中为 CHAR/VARCHAR 列定义游标时(我们为此使用包装器),绑定到列的字符串的大小必须至少比列的最大宽度大一。

e.g. Column Name: U_NAME Type: VARCHAR(30)

例如列名:U_NAME 类型:VARCHAR(30)

1. char zName[30]; pCursor->Define(zName, 3O); // this would crash if the column has a value with 30 chars

1. 字符 zName[30]; pCursor->Define(zName, 3O); // 如果该列的值包含 30 个字符,则会崩溃

2. char zName[31]; pCursor->Define(zName, 3O); // this would crash if the column has a value with 30 chars

2. 字符 zName[31]; pCursor->Define(zName, 3O); // 如果该列的值包含 30 个字符,则会崩溃

3. char zName[31]; pCursor->Define(zName, 31); // Correct. would not crash for any value

3. 字符 zName[31]; pCursor->Define(zName, 31); // 正确的。不会因任何值而崩溃

回答by Tony Andrews

You have a bug in your code, in that it only allows for 30 chars when it may receive 50. Why not just fix it rather than worry about which Oracle version the bug causes issues with?

您的代码中有一个错误,因为它只允许 30 个字符,而它可能会收到 50 个字符。为什么不直接修复它而不是担心该错误会导致哪个 Oracle 版本出现问题呢?