Solved

Oracle Number showing extra precision

Posted on 2013-11-12
4
569 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

743 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

15 Experts available now in Live!

Get 1:1 Help Now