Friday, October 19, 2012

TRUNC - Truncate Datetime - Oracle

In Oracle, TRUNC(datetimeunit) function allows you to truncate a datetime value to the specified unit (set zero time, set the first day of the month i.e)

Syntax
TRUNC(datetime [, unit])
Default Unit
'DD' truncates to day (sets zero time)

TRUNC function supports the following truncation units (full list...):
Oracle TRUNC Unit
Truncation
Result

'DD'
'DDD'
Day
YYYY-MM-DD 00:00:00

'MM'
'MONTH'
Month
YYYY-MM-01 00:00:00

'YY'
'YEAR'
Year
YYYY-01-01 00:00:00

'HH'
'HH24'
Hour
YYYY-MM-DD HH:00:00

'MI'
Minute
YYYY-MM-DD HH:MI:00


Example: In PeopleSoft below statement will all employee record where effective date is same as last update datetime, TRUNC method without any parameter will result the date value.

SELECT * FROM PS_JOB WHERE EFFDT = TRUNC(LASTUPDDTTM);

No comments:

Post a Comment