Upload
1raju1234
View
217
Download
0
Embed Size (px)
Citation preview
7/22/2019 TRUNC Function (With Dates)
1/1
Oracle/PLSQL: TRUNC Function (with dates)
In Oracle/PLSQL, the TRUNC functionreturns a date truncated to a specific unit of measure.
Syntax
The syntax for the TRUNC functionis:
TRUNC ( date, [ format ] )
dateis the date to truncate.
formatis the unit of measure to apply for truncating. If the formatparameter is omitted, the TRUNC functionwilltruncate the date to the day value, so that any hours, minutes, or seconds will be truncated off.
Below are the valid format parameters:
Unit Valid format parameters
Year SYYYY, YYYY, YEAR, SYEAR, YYY, YY, Y
ISO Year IYYY, IY, I
Quarter Q
Month MONTH, MON, MM, RM
Week WW
IW IW
W W
Day DDD, DD, J
Start day of the week DAY, DY, D
Hour HH, HH12, HH24
Minute MI
Applies To
Oracle 12c, Oracle 11g, Oracle 10g, Oracle 9i, Oracle 8i
For Example
The TRUNC functioncan be used in Oracle/PLSQL. For example:
TRUNC(TO_DATE('22-AUG-03'), 'YEAR') would return '01-JAN-03'
TRUNC(TO_DATE('22-AUG-03'), 'Q') would return '01-JUL-03'
TRUNC(TO_DATE('22-AUG-03'), 'MONTH') would return '01-AUG-03'
TRUNC(TO_DATE('22-AUG-03'), 'DDD') would return '22-AUG-03'
TRUNC(TO_DATE('22-AUG-03'), 'DAY') would return '17-AUG-03'