DB2 Scalar functions - DECIMAL or DEC
The DECIMAL function returns a decimal representation of a number, a string representation of a number, or a datetime value.
The schema is SYSIBM.
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 precision and a scale of scale. Digits are truncated from the end of the decimal number if the number of digits to the right of the decimal separator character is greater than the scale scale. An error is returned if the number of significant decimal digits required to represent the whole part of the number is greater than precision - scale (SQLSTATE 22003).
The string-expression is converted to the section code page if required to match the code page of the constant decimal-character.
The result is the same number that would result from CAST(string-expression AS DECIMAL(precision, scale)). Digits are truncated from the end of the decimal number if the number of digits to the right of the decimal separator character is greater than the scale scale. An error is returned if the number of significant digits to the left of the decimal character (the whole part of the number) in string-expression is greater than precision - scale (SQLSTATE 22003). The default decimal character is not valid in the substring if a different value for the decimal-character argument is specified (SQLSTATE 22018).
The result is the same number that would result from CAST(datetime - expression AS DECIMAL(precision, scale)). Digits are truncated from the end of the decimal number if the number of digits to the right of the decimal separator character is greater than the scale scale. An error is returned if the number of significant digits to the left of the decimal character (the whole part of the number) in string-expression is greater than precision - scale (SQLSTATE 22003).
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 CAST specification should be used to increase the portability of applications. For more information, see CAST specification.
SELECT EMPNO , DECIMAL(EDLEVEL,5,2) FROM EMPLOYEE
SELECT PRSTDATE + DECIMAL(:PERIOD,8) FROM PROJECT
UPDATE STAFF SET SALARY = DECIMAL(:newsalary, 9, 2, ',') WHERE ID = :empid;
DECIMAL('21400,50', 9, 2, '.')
DECIMAL(STARTING)
DECIMAL(RECEIVED)
The following table shows the decimal result and resulting precision and scale for various datetime input values.