Reputation: 1207
I run a SELECT query in .NET (using OracleDataAdapter) and SQL Developer. Result sets are slightly different:
SQL Developer returns:
.NET returns:
As you see, there is an extra 0 at the end of the values that have 1 or 3 digits after dot. What is the root cause of this problem and how to prevent it?
We can easily remove the extra 0 in code but we would like to prevent it by fixing the underlying issue. Thanks!
UPDATE (1/29/2018):
This is the .NET code to fetch the data:
OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings["conString"].ConnectionString);
if (conn.State != ConnectionState.Open)
conn.Open();
DataSet hereDataSet = new DataSet();
try
{
using (OracleCommand oCmd = new OracleCommand())
{
oCmd.Connection = conn;
oCmd.CommandText = "select V_COLUMN from T_TABLE where V_COLUMN='123'";
OracleDataAdapter oDataAdapter = new OracleDataAdapter(oCmd);
oDataAdapter.SelectCommand = oCmd;
oDataAdapter.Fill(hereDataSet);
}
}
catch (Exception ex)
{
// exception logic
}
finally
{
if (conn.State == ConnectionState.Open)
{ conn.Close(); }
}
Upvotes: 2
Views: 399
Reputation: 7465
Oracle stores numbers differently. Are you sure that the number you are getting back from oracle when going to .net decimal isnt 33641.70000000000001 for example. You might want to get one row with a debugger into a regular variable and hover over it (not ToString) to find out...if that is it, your solution since you want only 3 decimal places would be to explicitly round to 3. I've had to do this before.
Upvotes: 0
Reputation: 65574
As per the MSDN documentation: https://msdn.microsoft.com/en-us/library/fzeeb5cd.aspx
If format is null or an empty string, the return value of this instance is formatted with the general numeric format specifier (G).
I think what you want to do is:
var asExpected = oracleDataReader.GetDecimal(0).ToString("G0");
Upvotes: 2