NUMERIC and DECIMAL Data Types
Go Up to Understanding the XSQLDA (Embedded SQL Guide)
DECIMAL
and NUMERIC
data types are stored internally as SMALLINT
, INTEGER
, DOUBLE PRECISION
, or 64-bit integer data types, depending on the precision and scale defined for a column definition that uses these types. To determine how a DECIMAL
or NUMERIC
value is actually stored in the database, use isql
to examine the column definition in the table. If NUMERIC
is reported, then data is actually being stored as a 64-bit integer.
When a DECIMAL
or NUMERIC
value is stored as a SMALLINT
or INTEGER
, the value is stored as a whole number. During retrieval in DSQL, the sqlscale
field of the XSQLVAR
is set to a negative number that indicates the factor of ten by which the whole number (returned in sqldata
), must be divided in order to produce the correct NUMERIC
or DECIMAL
value with its fractional part. If sqlscale
is –1, then the number must be divided by 10, if it is –2, then the number must be divided by 100, –3 by 1,000, and so forth.