SQL-J Language Reference
Page 73 of 121

EXTRACT

EXTRACT extracts the specified field from a date/time expression as an integer or double-precision value.

Syntax

EXTRACT (Field FROM DateTimeExpression)

The fields available for extraction depend on the date/time type that EXTRACT is applied to, as listed in Table 1-5, "Extractable Fields in Date/Time Data Types"

Table 1-5 Extractable Fields in Date/Time Data Types

Field

DATE

TIME

TIMESTAMP

YEAR

X


X

MONTH

X


X

DAY

X


X

HOUR


X

X

MINUTE


X

X

SECOND


X

X

.

The result type of EXTRACT is INTEGER except when extracting SECOND from a TIMESTAMP. In the current release, the result type of extracting SECOND from a TIMESTAMP is DOUBLE PRECISION. The result type of extracting SECOND from a TIME is an INT.

EXTRACT Example

-- returns 1
VALUES EXTRACT(MONTH FROM DATE'1995-01-01')