Syntax

 

<extract expression> ::=

 

 

 

EXTRACT ( <extract field> FROM <extract source> )

 

<extract field> ::= <primary datetime field>

 

<extract source> ::= <datetime value expression>

 

 

Notes

 

The EXTRACT function returns the datetime field specified by <extract field> from the <extract source>.



 

If SECOND is specified as extract field, then the data type of the result is DOUBLE PRECISION, else the data type of the result is INTEGER.



 

If either of the arguments are null, then the result is null.



 

 

Examples

 

1) The following example extracts the YEAR, MONTH and DAY fields from the orderDate column:

 


SELECT




orderID,


EXTRACT( YEAR FROM orderDate ) AS "Year",




EXTRACT( MONTH from orderDate ) AS "Month",


EXTRACT( DAY FROM orderDate ) AS "Day",




orderTotal




FROM orders

 

2) The following example groups order totals by year:



 


SELECT




"Year",


SUM( orderTotal ) AS "Total Amount"




FROM


(




SELECT




EXTRACT( YEAR FROM orderDate ) AS "Year",




orderTotal




FROM orders




) AS orders


GROUP BY "Year"



 

 


 

Conformance

 

SQL:2003 standard

-

Feature F052 "Intervals and datetime arithmetic"