Oracle TRUNC(number) Function
Oracle TRUNC(number) is a built-in function that truncates the specified number to the specified precision (0 by default) and returns the result.
Oracle TRUNC(number) syntax
Here is the syntax for the Oracle TRUNC(number) function:
TRUNC(number [, scale ])
Parameters
number-
Required. A number, which can be positive, negative, or zero, and can be an integer or a decimal.
scale-
Optional. An integer representing the precision of the number. Default is
0.
Return Value
The Oracle TRUNC(number) function truncates the specified number to the specified precision (0 by default) and returns the result.
If any parameter is NULL, TRUNC(number) will return NULL.
Oracle TRUNC(number) Examples
Here are some examples that demonstrate the usage of the Oracle TRUNC(number) function.
Basic Usage
SELECT
TRUNC(1.2345),
TRUNC(1.2345, 1),
TRUNC(1.2345, 3)
FROM dual;
Output:
TRUNC(1.2345) TRUNC(1.2345,1) TRUNC(1.2345,3)
________________ __________________ __________________
1 1.2 1.234Negative numbers
Oracle TRUNC(number) functions allow you to provide a negative number for the second parameter to truncate the integer part.
SELECT
TRUNC(12345, -1),
TRUNC(12345, -2)
FROM dual;
Output:
TRUNC(12345,-1) TRUNC(12345,-2)
__________________ __________________
12340 12300NULL Parameters
If any parameter is NULL, TRUNC() will return NULL.
SET NULL 'NULL';
SELECT
TRUNC(1, NULL),
TRUNC(NULL, 1),
TRUNC(NULL, NULL)
FROM dual;
Output:
TRUNC(1,NULL) TRUNC(NULL,1) TRUNC(NULL,NULL)
________________ ________________ ___________________
NULL NULL NULLIn this example, we use the statement SET NULL 'NULL'; to display NULL values as the string 'NULL'.
Conclusion
Oracle TRUNC(number) is a built-in function that truncates the specified number to the specified precision (0 by default) and returns the result.