Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Oracle Number showing extra precision

Posted on 2013-11-12
4
Medium Priority
?
596 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
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…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
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…
Suggested Courses

916 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