The TRUNC Function

The TRUNC function is used to truncate or trim values to a specified precision. The function contains two parameters: the target column or value and the specified precision. Specifying a precision of 2 will cause the value to be truncated following the hundredths. A precision of –2 will cause the value to be truncated following the hundred. Listing 7.5 illustrates a query that uses the TRUNC function. Compare the results of this query to the values in Listing 7.4.

Listing 7.5. Using the TRUNC Function
 SQL> select last_name, wages/3, trunc(wages/3,2), trunc(wages/3,-2) 2 from employee 3 where fk_department='INT' 4 group by last_name, wages; LAST_NAME WAGES/3 TRUNC(WAGES/3,2) TRUNC(WAGES/3,-2) --------------- --------- ---------------- ...

Get Oracle SQL and PL/SQL Handbook: A Guide for Data Administrators, Developers, and Business Analysts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.