tags:

views:

2969

answers:

4

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.

A: 

TO_NUMBER is what you want, specifically the TO_NUMBER('42', '99') version.

Hank Gay
Just tried this, although the values within Oracle are integers. The output into the DataTable is still a decimal.
JDunkerley
A: 

You can always turn the decimal into an integer using the round function (or the trunc or floor functions)

Jordi Cabot
A: 
CAST(field AS integer)
Patrick McDonald
+2  A: 

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.)

Aaron Daniels