The EXTRACT function returns a single date-time field expressed
as an integer from a column of data type DATE, TIME, TIMESTAMP,
or INTERVAL.
The date-time fields that EXTRACT can return are:
o YEAR
o MONTH
o DAY
o HOUR
o MINUTE
o SECOND
o WEEKDAY
o JULIAN
o WEEK_NUMBER
o YEAR_WEEK
The data type returned is a signed longword of scale 0, unless
the date-time field is SECOND. If the SECOND field is selected,
then the scale is set to 2.
If you specify WEEKDAY, you can only use the data types TIMESTAMP
and DATE as the extract source. In all other cases, the extract
source can be data type DATE, TIME, TIMESTAMP, or INTERVAL. If
you specify WEEKDAY, then the EXTRACT function returns an integer
representing the day of the week. (Monday is represented as day
1, Sunday as day 7.)
If the EXTRACT function is applied to a null value, it returns a
null value.
The number of days since the first day of a year, called
the Julian date, can be an important integer value to which
programmers need direct access. The SQL EXTRACT function lets you
determine the Julian date from column data defined with date-time
data types.
The JULIAN keyword requires that the extract expression resolve
to either the DATE ANSI or TIMESTAMP date-time data type. Value
expressions that do not resolve to one of these particular data
types will fail. For example, trying to extract the Julian date
from an expression defined by the CURRENT_TIME data type results
in the following SQL error message:
SQL> SELECT EXTRACT(JULIAN FROM CURRENT_TIME) FROM ACCOUNTING.DAILY_HOURS;
%RDB-F-CONVERT_ERROR, invalid or unsupported data conversion
-RDMS-E-EXT_JULIAN_TS, invalid type for EXTRACT JULIAN, must be DATE or
TIMESTAMP
SQL>
You cannot represent dates from the year 1858 using the JULIAN
keyword in the EXTRACT function because JULIAN calculates from
1-January and the first date in 1858 is 18-November.
The options WEEK_NUMBER and YEAR_WEEK return the week number
as defined by the International Standard ISO 8601:1988 "Data
elements and interchange formats - Information interchange -
Representation of dates and times".
WEEK_NUMBER is a number between 1 and 53 representing the week of
the year (most years only have 52 weeks). A week starts on Monday
and has most of its days falling in a specific year.
YEAR_WEEK is a variation of the WEEK_NUMBER that includes the
year (including the century) in which the week logically falls.
The values range from 185901 through 999952 (higher values are
possible if dates are constructed with a year beyond 9999). The
last two digits of the value are identical to the value returned
by the WEEK_NUMBER option.