SQL - Scalar functions - TRUNCATE or TRUNC
The TRUNCATE function returns a truncated value of a number or a datetime value.
The schema is SYSIBM. The SYSFUN version of the TRUNCATE numeric function continues to be available.
The data type of the return value depends on the first argument:
If the expression is a decimal floating-point data type, the DECFLOAT rounding mode will not be used. The rounding behavior of TRUNCATE corresponds to a value of ROUND_DOWN. If a different rounding behavior is wanted, use the QUANTIZE function.
If numeric-expression2 is not negative, numeric-expression1 is truncated to the absolute value of numeric-expression2 number of places to the right of the decimal point.
If numeric-expression2 is negative, numeric-expression1 is truncated to the absolute value of numeric-expression2 + 1 number of places to the left of the decimal point. If the absolute value of a negative numeric-expression2 is larger than the number of digits to the left of the decimal point, the result is 0. For example:
TRUNCATE(748.58,-4) = 0
The data type, length, and scale attributes of the result are the same as the data type, length, and scale attributes of the first argument.
If either argument can be null, the result can be null. If either argument is null, the result is the null value.
Allowable values for format-string are listed in the table of format elements found in the description of the ROUND function.
The data type and length attribute of the result are the same as the data type and length attribute of the first argument.
The result can be null if the argument can be null or if the argument is not a decimal floating-point number and the database is configured with dft_sqlmathwarn set to YES; the result is the null value if the argument is null.
SELECT TRUNCATE(MAX(SALARY)/12,2) FROM EMPLOYEE;
VALUES ( TRUNCATE(873.726,2), TRUNCATE(873.726,1), TRUNCATE(873.726,0), TRUNCATE(873.726,-1), TRUNCATE(873.726,-2), TRUNCATE(873.726,-3) );
VALUES(TRUNCATE(DECFLOAT(873.726),0))
SET vTRNK_DT = TRUNC(DATE('2000-08-16'), 'MONTH');
SET :TRNK_TMSTMP = TRUNCATE('2000-03-14-17.30.00'), 'YEAR');