Re: losing precision while selecting NUMBER values from Oracle 7.3

From: Tim Bunce (Tim.Bunce_at_pobox.com)
Date: 09/21/04


Date: Tue, 21 Sep 2004 22:05:19 +0100
To: Ravi Kongara <Ravi.Kongara@Sun.COM>

On Tue, Sep 21, 2004 at 12:30:17PM -0700, Ravi Kongara wrote:
> Hi,
>
> I'm using DBI 1.42, DBD::Oracle1.14 built on Oracle 8, Perl 5.6.1 on
> Solaris 9.
> Purpose of the script is to compare values between source and target
> databases.
> Source db is Oracle 7.3 and target db is Oracle 8.1.7.
> Again and again i'm getting into the problem of losing precision/scale
> of NUMBER values.
> DBI script selects/displays 39 digits after the decimal point,
> eventhough database has stored 40 digits, cutting off
> last digit while selecting from source. Strangely, it displays all 40
> digits from target, which is a Oracle 8 database.
>
> When i select from SQLPLUS session, values are shown correctly. Both
> source and target show 40 digits and they match.
> Is there any clue what's happening..? why the last digit is lost when i
> select using DBI from Oracle 7.

DBD::Oracle simply asks for the columns as strings and it's Oracle itself
that performs the number to string conversion. DBD::Oracle gives
Oracle a buffer of 133 characters for NUMBER fields, so there's
pleanty of room to store the number.

> If, i use TO_CHAR function i get 39 digits from both source and target.

That's a key point. Oracle itself is happy to truncate the number.

I'm not sure why SQLPLUS behaves differently. It probably asks
Oracle to fetch the NUMBR as a raw number and then uses OCI library
functions to format it. That different code path may be the cause
of the different behaviour.

Tim.

> Code snippet
> --------------------------
> <. . . . . >
> use DBI;
> use Getopt::Long;
>
> my $src_test_value = $src_dbh->selectrow_array("select
> CONVERSION_RATE from $src_schema_name.$src_table_name where
> FROM_CURRENCY_CODE = 'ZAR' and conversion_date = (select
> max(conversion_date) from $src_schema_name.$src_table_name where
> FROM_CURRENCY_CODE = 'ZAR')");
> print "src conv rate = $src_test_value\n";
>
> my $tgt_test_value = $tgt_dbh->selectrow_array("select
> CONVERSION_RATE from $ods_schema_name.$ods_table_name where
> FROM_CURRENCY_CODE = 'ZAR' and conversion_date = (select
> max(conversion_date) from $ods_schema_name.$ods_table_name where
> FROM_CURRENCY_CODE = 'ZAR')");
> print "ods conv rate = $tgt_test_value\n";
> <. . . . . . >
> --------------------------
> values printed are...
>
> Comparing src -> tgt
> src conv rate = .159616919393455706304868316041500399042
> ods conv rate = .1596169193934557063048683160415003990423
> ------------------------------------------------------
>
>
> Thanks,
> Ravi
>



Relevant Pages

  • Single application - multiple target databases - which DB driver?
    ... I'd be interested in peoples thoughts on which database driverto ... use for an application where the target db varies.... ... Currently our main application is Oracle based using Direct Oracle ... particularly users of SQLDirect ...
    (borland.public.delphi.thirdpartytools.general)
  • losing precision while selecting NUMBER values from Oracle 7.3
    ... Source db is Oracle 7.3 and target db is Oracle 8.1.7. ... DBI script selects/displays 39 digits after the decimal point, ... which is a Oracle 8 database. ...
    (perl.dbi.users)
  • CProviderTypes - Doubt
    ... I need to create some intermediate temp tables in the target ... database as same as the source. ... Server's but again it should be compatible for oracle. ... getting the right data type bcos OLEDB gives data type number to a group ...
    (microsoft.public.data.oledb)
  • Re: What so special about PostgreSQL and other RDBMS?
    ... That's exactly the link the licence agreement for the database points to when it ... comes to what wecan expect for paying support. ... > "Oracle may provide additional releases or versions of its programs ... If the requirements are volatile I'd do a long term contract detailing what ...
    (comp.lang.php)
  • A cool DBA job wanted
    ... 7, Oracle 6, Sybase, SQL Server ... Proposed proactive database monitoring through ... strategies to administer remote Oracle databases ... Trained installation and support personnel in basic ...
    (comp.databases.oracle.server)