ora-01406 Error when fetching values using OCI

2019-08-01 18:25发布

问题:

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

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?

The Oracle versions we use are 10.2.0.1 and 10.2.0.3

回答1:

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

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.

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

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

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

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



回答2:

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?



标签: oracle oci