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.
The default for the precision-integer depends on the data type of the numeric-expression:
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.
The character-expression is converted to the database code page if required to match the code page of the constant decimal-character.
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:
SELECT EMPNO, DECIMAL(EDLEVEL,5,2) FROM EMPLOYEE
SELECTPRSTDATE + DECIMAL(:PERIOD,8) FROM PROJECT
UPDATE STAFF SET SALARY = DECIMAL(:newsalary, 9, 2, ',') WHERE ID = :empid;
The value of newsalary becomes 21400.50.
DECIMAL('21400,50', 9, 2, '.')
This fails because a period (.) is specified as the decimal character but a comma (,) appears in the first argument as a delimiter.