Solved

Oracle Number showing extra precision

Posted on 2013-11-12
4
572 Views
Last Modified: 2013-11-12
drop table temp_geoff;
create table temp_geoff (Numeric_TEST                   NUMBER(14,2));
grant all on temp_geoff  to public ;
insert into temp_geoff(Numeric_TEST) values (4000.99);
insert into temp_geoff(Numeric_TEST) values (0);
insert into temp_geoff(Numeric_TEST) values (2077.49);
commit;

To test the returnset, use the following in a c# console app that includes a reference to Oracle...
var connString = "Data Source= (DESCRIPTION =);User Id=zzUser;Password=zzPassword;";
DataSet ds = new DataSet();
OracleConnection conn = new OracleConnection(connString);
OracleCommand cmd = conn.CreateCommand();
cmd.CommandText = "Select Numeric_TEST from temp_geoff";
cmd.CommandType = CommandType.Text;
OracleDataAdapter da = new OracleDataAdapter(cmd);
da.Fill(ds);
conn.Close();
conn.Dispose();
ds.WriteXml(AppDomain.CurrentDomain.BaseDirectory + @"\ds_1.txt");
Process.Start("notepad.exe", AppDomain.CurrentDomain.BaseDirectory + @"\ds_1.txt");

These are the results regardless of which driver I choose...
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <Table>
    <NUMERIC_TEST>4000.9900000000002</NUMERIC_TEST>
  </Table>
  <Table>
    <NUMERIC_TEST>0</NUMERIC_TEST>
  </Table>
  <Table>
    <NUMERIC_TEST>2077.4900000000002</NUMERIC_TEST>
  </Table>
</NewDataSet>

Oracle Drivers tested include
Oracle.DataAccess.dll v 2.121.1.0
Oracle.DataAccess.dll v 2.112.3.0
Oracle.DataAccess.dll v 2.112.2.0
0
Comment
Question by:gswitz
  • 3
4 Comments
 
LVL 10

Accepted Solution

by:
joriszwaenepoel earned 500 total points
ID: 39641773
The dataset is probably created with a DOUBLE datatype instead of a DECIMAL datatype for the numeric column.

You can probably avoid this by using the da.FillSchema method and then changing the datatype of that specific column to GetType(Decimal).

After that, you can use da.Fill to get the data in the correct type.
0
 

Author Closing Comment

by:gswitz
ID: 39641856
http://www.experts-exchange.com/Programming/Languages/.NET/Q_28291973.html

I created a new one to learn how to alter it. I've written the schema to the dataset. I just need to know how to change it.
0
 

Author Comment

by:gswitz
ID: 39641865
While you were correct about the type defined in the schema, when there is no precision defined on the number in Oracle the dataset type is still Double but the problem does not exist.
<?xml version="1.0" standalone="yes"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="Table">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="A" type="xs:double" minOccurs="0" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>
0
 

Author Comment

by:gswitz
ID: 39641872
Nope. I was wrong. Just had to restart the debugger. When the precision is NOT defined in Oracle, then it creates a dataset schema column type of deciimal.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now