SQL Reference

DECIMAL

Numeric to Decimal:

>>-+-DECIMAL-+--(--numeric-expression--------------------------->
   '-DEC-----'
 
>-----+-----------------------------------------------+--)-----><
      '-,--precision-integer--+--------------------+--'
                              '-,--scale-integer---'
 

Character to Decimal:

>>-+-DECIMAL-+--(--character-expression------------------------->
   '-DEC-----'
 
>-----+----------------------------------------------------------------------------+>
      '-,--precision-integer--+-------------------------------------------------+--'
                              '-,--scale-integer----+------------------------+--'
                                                    '-,--decimal-character---'
 
>----)---------------------------------------------------------><
 

The schema is SYSIBM.

The DECIMAL function returns a decimal representation of

The result of the function is a decimal number with precision of p and scale of s, where p and s are the second and third arguments. If the first argument can be null, the result can be null; if the first argument is null, the result is the null value.

Numeric to Decimal

numeric-expression
An expression that returns a value of any numeric data type.

precision-integer
An integer constant with a value in the range of 1 to 31.

The default for the precision-integer depends on the data type of the numeric-expression:

  • 15 for floating-point and decimal
  • 19 for big integer
  • 11 for large integer
  • 5 for small integer.

scale-integer
An integer constant in the range of 0 to the precision-integer value. The default is zero.

The result is the same number that would occur if the first argument were assigned to a decimal column or variable with a precision of p and a scale of s, where p and s are the second and third arguments. An error occurs if the number of significant decimal digits required to represent the whole part of the number is greater than p-s.

Character to Decimal

character-expression
An expression that returns a value that is a character string with a length not greater than the maximum length of a character constant (4 000 bytes). It cannot have a CLOB or LONG VARCHAR data type. Leading and trailing blanks are eliminated from the string. The resulting substring must conform to the rules for forming an SQL integer or decimal constant (SQLSTATE 22018).

The character-expression is converted to the database code page if required to match the code page of the constant decimal-character.

precision-integer
An integer constant with a value in the range 1 to 31 that specifies the precision of the result. If not specified, the default is 15.

scale-integer
An integer constant with a value in the range 0 to precision-integer that specifies the scale of the result. If not specified, the default is 0.

decimal-character
Specifies the single byte character constant that is used to delimit the decimal digits in character-expression from the whole part of the number. The character cannot be a digit plus ('+'), minus ('-') or blank and can appear at most once in character-expression (SQLSTATE 42815).

The result is a decimal number with precision p and scale s where p and s are the second and third arguments. Digits are truncated from the end if the number of digits right of the decimal character is greater than the scale s. An error occurs if the number of significant digits left of the decimal character (the whole part of the number) in character-expression is greater than p-s (SQLSTATE 22003). The default decimal character is not valid in the substring if the decimal-character argument is specified (SQLSTATE 22018).

Examples:


[ Top of Page | Previous Page | Next Page ]