Link to home
Start Free TrialLog in
Avatar of gswitz
gswitz

asked on

Oracle Number showing extra precision

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
ASKER CERTIFIED SOLUTION
Avatar of joriszwaenepoel
joriszwaenepoel
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gswitz
gswitz

ASKER

https://www.experts-exchange.com/questions/28291973/The-dataset-is-created-with-a-DOUBLE-datatype-instead-of-a-DECIMAL-datatype-for-the-numeric-column.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.
Avatar of gswitz

ASKER

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>
Avatar of gswitz

ASKER

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.