Oracle TRUNC Date Function Guide
In Oracle, the TRUNC function can be used to manipulate dates. It truncates the time portion of a date, setting it to zero while keeping only the date part. Here is an example of using the TRUNC function to handle dates:
- Set the time part of the date to zero.
SELECT TRUNC(SYSDATE) FROM dual;
This will return the date part of the current date, with the time part set to zero.
- Cut off the month.
SELECT TRUNC(SYSDATE, 'MM') FROM dual;
This will return the first day of the current month.
- Year cut-off:
SELECT TRUNC(SYSDATE, 'YYYY') FROM dual;
This will return the first day of the current year.
In addition to the examples above, the TRUNC function can also accept other parameters such as ‘DD’ (truncate to day), ‘HH’ (truncate to hour), ‘MI’ (truncate to minute), etc. Depending on specific needs, you can choose the appropriate parameters to handle dates.