Let's Truncate Dates!



TRUNC

Syntax: TRUNC ( source date [, date precision format ] )

Parameters: source date is the date which is to be truncated. Data precision format is the unit of measure to apply for truncating. It is an optional parameter. If date precision format is omitted, the TRUNC function will truncate the date to the day value. Date precision formats include century (CC), year (YYYY), quarter (Q), month (MM), week (W), day (DD), hour (HH), and minute (MI).

Return type: The TRUNC function (as it applies to dates) returns date value.

Usage: According to company's policy, the start date of the health insurance of the employees will start from the 1st day of the month of their joining date. Manager to Data analyst: Bring me the list of all employees with the start date of their health insurance. Data analyst runs below query to fetch the required data.


SELECT EMPLOYEE_ID, FIRST_NAME, LAST_NAME, TRUNC(HIRE_DATE, ‘MM’) FROM EMPLOYEES;







Comments

Popular posts from this blog

Let's learn Cross Join!

Full Outer Join!

Let's extract STRING!