I am trying to parse a column of strings in Oracle (version 8i) to an integer.
I am accessing the results through Oracle.DataAccess library
I'm already using TO_NUMBER
with a mask to convert the string into a number with no decimal places. The problem is that the value in the client code is being retrieved as a decimal rather than an int.
CAST(field AS integer)
NUMBER columns always come back as decimals in ODP.NET. To get around this, pull it back as an OracleDecimal, which has several "Toxxxx" methods to cast the value into the native .NET type you need.
while (myOracleDataReader.Read())
{
int x = myOracleDataReader.GetOracleDecimal(0).ToInt32();
}
(Forgive me if the code above isn't 100% correct, as I don't have ODP.NET installed at home.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With