The TRUNC function in Oracle SQL / PLSQL is used to get a number truncated to specific number of decimal places.
Syntax for the TRUNC function in Oracle SQL / PLSQL is:
SELECT TRUNC(N,D)
FROM table_name;
- N is the number to be truncated
- D is the decimal places up to which N is to be truncated
Example 1:
1 | SELECT TRUNC(1.23456,4) |
2 | FROM DUAL; |
Will return “1.2345”
Example 2:
1 | SELECT TRUNC(1.23456,3) |
2 | FROM DUAL; |
Will return “1.234”
Example 3:
1 | SELECT TRUNC(1.23456,2) |
2 | FROM DUAL; |
Will return “1.23”
Example 4:
1 | SELECT TRUNC(-1.23456,3) |
2 | FROM DUAL; |
Will return “-1.234”
Example 5:
1 | SELECT TRUNC(1.23456) |
2 | FROM DUAL; |
Will return “1”