天天看点

Oracle EXTRACT (datetime) EXTRACT (datetime)

Oracle EXTRACT (datetime) EXTRACT (datetime)

<a target="_blank" href="http://docs.oracle.com/cd/b19306_01/server.102/b14200/img_text/extract_datetime.htm">description of the illustration extract_datetime.gif</a>

<code>extract</code> extracts and returns the value of a specified datetime field from a datetime or interval value expression. when you extract a <code>timezone_region</code> or<code>timezone_abbr</code> (abbreviation),

the value returned is a string containing the appropriate time zone name or abbreviation. when you extract any of the other values, the value returned is in the gregorian calendar. when extracting from a datetime with a time zone value, the value returned

is in utc. for a listing of time zone names and their corresponding abbreviations, query the <code>v$timezone_names</code> dynamic performance view.

this function can be very useful for manipulating datetime field values in very large tables, as shown in the first example below.

note:

timezone region names are needed by the daylight savings feature. the region names are stored in two time zone files. the default time zone file is a small file containing only the most common time zones to maximize performance. if your time zone is not in

the default file, then you will not have daylight savings support until you provide a path to the complete (larger) file by way of the <code>ora_tzfile</code> environment variable.

some combinations of datetime field and datetime or interval value expression result in ambiguity. in these cases, oracle database returns <code>unknown</code> (see the examples that follow for additional information).

the field you are extracting must be a field of the <code>datetime_value_expr</code> or <code>interval_value_expr</code>.

for example, you can extract only <code>year</code>, <code>month</code>, and <code>day</code> from a<code>date</code> value. likewise, you can extract <code>timezone_hour</code> and <code>timezone_minute</code> only

from the <code>timestamp</code> <code>with</code> <code>time</code> <code>zone</code> datatype.

see also:

of <code>datetime_value_expr</code> and <code>interval_value_expr</code>

the following example returns from the <code>oe.orders</code> table the number of orders placed in each month:

the following example returns the year 1998.

the following example selects from the sample table <code>hr.employees</code> all employees who were hired after 1998:

the following example results in ambiguity, so oracle returns <code>unknown</code>:

the ambiguity arises because the time zone numerical offset is provided in the expression, and that numerical offset may map to more than one time zone region.