Introduction
SQL, or Structured Query Language, is a standard language for managing data held in a relational database management system. It's a robust language with a plethora of functions to help us in data manipulation and retrieval. One such function is the TRUNC function.

This article will take you through what the TRUNC function is, how to use it, and some practical examples of its use in SQL queries.
What is the TRUNC Function?
TRUNC stands for 'truncate.' In the context of SQL, this function is used to truncate a number to a certain number of decimal places or to truncate a date to a specified unit.
The syntax for using the TRUNC function with numbers is:
TRUNC(number, decimal_places)
When using the TRUNC function with dates, the syntax becomes:
TRUNC(date, format)
Truncating Numbers
The TRUNC function can be used with numbers to truncate them to a certain number of decimal places. For example, if you want to truncate the number 123.456 to one decimal place, you would use:
The output of this query would be 123.4.

Truncating Dates
The TRUNC function is also often used with dates. When used with a date, the TRUNC function can truncate the date to the specified format.
For example, to truncate the date to the year, you would use:
SELECT TRUNC(TO_DATE('13-OCT-21', 'DD-MON-YY'), 'YEAR') FROM dual;
The output of this query would be 01-JAN-21.

Practical Examples
Let's look at a practical example using the TRUNC function in the context of a real database. Suppose you have a table named 'Orders' with the following data as given below in the orders table.
If you wanted to get the total income from each day, but without considering the cents, you could use the TRUNC function like this:

SELECT OrderDate, TRUNC(SUM(Quantity * Price)) as TotalIncome
FROM Orderss
GROUP BY OrderDate;
This will give you the total income per day, truncated to the nearest whole number.

Also read, Natural Join in SQL