Oracle’s TRUNC(date) function removes the time portion or higher-level date parts (month, year, etc.) from a DATE or TIMESTAMP value.
TRUNC(date) strips unwanted time or higher-level date parts, returning the date portion you specify. It simplifies grouping, filtering, and comparison by normalizing timestamps to a common boundary.
Call TRUNC(order_date). Oracle drops the hours, minutes, and seconds, yielding the date at 00:00:00. Use this when grouping daily sales from the Orders table.
Provide a format mask: TRUNC(order_date, 'MM').This resets day and time, helpful for monthly revenue summaries.
Use format masks 'YYYY' or 'Q'. Example: TRUNC(order_date, 'YYYY') for fiscal-year comparisons; TRUNC(order_date, 'Q') for quarterly KPIs.
Yes. For hours, TRUNC(order_date, 'HH24'); for minutes, TRUNC(order_date, 'MI'). Useful when analyzing intraday traffic spikes.
TRUNC always floors to the boundary, while ROUND may roll forward.Prefer TRUNC when you must not cross the boundary—e.g., daily sales must stay inside the same day.
1) Index on truncated columns for performance. 2) Keep format masks in UPPERCASE. 3) Document why truncation is needed to avoid hidden time-zone issues.
Select TRUNC(order_date) AS sale_day, SUM(total_amount) FROM Orders GROUP BY TRUNC(order_date) ORDER BY sale_day;
Using TRUNC in WHERE without function-based index: causes full scans; create index ON Orders (TRUNC(order_date)).
Forgetting second argument: TRUNC(order_date, 'MM') not TRUNC(order_date,'MON').The latter fails.
.
Yes. Given identical inputs, it always returns the same output, making it safe for function-based indexing.
No. It only alters the result in the query; the stored value remains intact.
TRUNC works on the stored session time zone. Convert to UTC first if you need cross-zone consistency.