apache > db
Apache DB Project
 
Font size:      

DECIMAL

DECIMAL

DECIMAL provides an exact numeric in which the precision and scale can be arbitrarily sized. You can specify the precision (the total number of digits, both to the left and the right of the decimal point) and the scale (the number of digits of the fractional component). The amount of storage required is based on the precision.

Syntax

{ DECIMAL | DEC } [(precision [, scale ])]

The precision must be between 1 and 31. The scale must be less than or equal to the precision.

If the scale is not specified, the default scale is 0. If the precision is not specified, the default precision is 5.

An attempt to put a numeric value into a DECIMAL is allowed as long as any non-fractional precision is not lost. When truncating trailing digits from a DECIMAL value, Derby rounds down.

For example:

-- this cast loses only fractional precision
values cast (1.798765 AS decimal(5,2));
1
--------
1.79
-- this cast does not fit
values cast (1798765 AS decimal(5,2));
1
--------
ERROR 22003: The resulting value is outside the range 
for the data type DECIMAL/NUMERIC(5,2).

When mixed with other data types in expressions, the resulting data type follows the rules shown in Numeric Type Promotion in Expressions.

See also Storing Values of One Numeric Data Type in Columns of Another Numeric Data Type.

When two decimal values are mixed in an expression, the scale and precision of the resulting value follow the rules shown in Scale for Decimal Arithmetic.

Corresponding Compile-Time Java Type

java.math.BigDecimal

JDBC Metadata Type (java.sql.Types)

DECIMAL

Examples

VALUES 123.456
 
VALUES 0.001

Integer constants too big for BIGINT are made DECIMAL constants.


Previous Page
Next Page
Table of Contents
Index