Error Arithmetic overflow when datareader read a NUMBER column (without prec nor scale) and the number is a float/double
rferraton opened this issue · 3 comments
When trying to read data from a NUMBER(null,null) column that contains a float we have the following error
- Message : Arithmetic operation resulted in an overflow.
- StackTrace : at Oracle.ManagedDataAccess.Types.DecimalConv.GetDecimal(Byte[] bytes, Int32 dataPos, Int32 length) at Oracle.ManagedDataAccess.Types.DecimalConv.GetDecimal(Byte[] bytes, Int32 dataPos, Int32 length, Boolean bSuppressOverflowException)
To reproduce :
CREATE TABLE TEST (COLNUMBER NUMBER);
INSERT INTO TEST VALUES (1);
INSERT INTO TEST VALUES (10000000.1234567890123);
INSERT INTO TEST VALUES (10000000.1234567890123456789);
INSERT INTO TEST VALUES (394083.621948664482634532982942036798611);
COMMIT;As the NUMBER datatype can have from int up to a Double data, the converter should be a DoubleConv no ?
The last number is 39 precision, which is pretty much the maximum of Oracle NUMBER. The .NET Decimal has a max precision of 28 digits, which is why you are likely seeing the overflow error. I don't think the problem is the .NET data type is a float. It's just too large for the .NET data type you're trying to set its value to.
If you enable the SuppressGetDecimalInvalidCastException property, ODP.NET will round off the number and retrieve it without generating an exception. This property can be set on the Oracle configuration, connection, data adapter, or data reader classes.
Thanks !!!
The SuppressGetDecimalInvalidCastException works greatly !