Re: C equivalent for Oracle NUMBER data type ?

From: Tim Smith <tssmith_at_netcom.com>
Date: Tue, 13 Jul 1993 14:24:19 GMT
Message-ID: <tssmithCA3xCJ.5oE_at_netcom.com>


In article <1993Jul13.091233.1_at_aa.wl.com> ditommm_at_aa.wl.com (Mr. Matteo diTommaso) writes:
>In article <CA3MnC.KJJ_at_uk.ac.brookes>, p0070621_at_oxford-brookes.ac.uk (Tommy Wareing) writes:
>> Ernst Kloecker (ernst_at_cs.tu-berlin.de) wrote:
>>> What is a safe C equivalent for the Oracle data type number ? I am
>>> generating NUMBERs from a SEQUENCE and need to store them in C
>>> variables safely. (I am using a VARCHAR[40] right now, is that o.k. ?)
>>
>> As far as I know, you have to convert them to character format.
>> Bleurgh :-(
>> So yes, VARCHAR[40] is correct. Or any equivalent string type.
>
>#include <stdio.h>
>#include <ctype.h>
>
>int errrpt(void);
>
>EXEC SQL BEGIN DECLARE SECTION;
>int counter;
>long int enum;
>float hill;
>VARCHAR gcoef[30];
>EXEC SQL END DECLARE SECTION;
>
>Take your pick. Of course you should not use int if you are working
>with numbers that exceed the size of int on your machine.

A couple of comments. The Oracle internal NUMBER format gives you a maximum of 38 decimal digits of precision, so in some (admittedly rare) cases you could lose precision with chars or varchars only 30 characters long. Varchar[40] (or char[40]) will always work.

Floats will always have their well-known problems. That is, you can represent 0.10 exactly using Oracle NUMBERs, but not with floats. Because of its internal NUMBER format, Oracle does not need a special datatype for monetary computations.

Conversion between character strings and NUMBERs (in or out) is automatic. You don't have to do anything special. Received on Tue Jul 13 1993 - 16:24:19 CEST

Original text of this message