Criar uma Loja Virtual Grátis
L'Oracle voir ce complet film avec sous-titres bonne qualite

EXTRACT (datetime)

EXTRACT extracts and returns the value of a specified datetime field from a datetime or interval value expression. When you extract a TIMEZONE_REGION or TIMEZONE_ABBR (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 V$TIMEZONE_NAMES 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.

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 ORA_TZFILE environment variable.

Some combinations of datetime field and datetime or interval value expression result in ambiguity. In these cases, Oracle Database returns UNKNOWN (see the examples that follow for additional information).

The field you are extracting must be a field of the datetime_value_expr or interval_value_expr. For example, you can extract only YEAR. MONTH. and DAY from a DATE value. Likewise, you can extract TIMEZONE_HOUR and TIMEZONE_MINUTE only from the TIMESTAMP WITH TIME ZONE datatype.

Oracle Database Administrator's Guide for more information about setting the ORA_TZFILE environment variable

Oracle Database Globalization Support Guide. for a complete listing of the timezone region names in both files

"Datetime/Interval Arithmetic" for a description of datetime_value_expr and interval_value_expr

Oracle Database Reference for information on the dynamic performance views

The following example returns from the oe.orders table the number of orders placed in each month:

The following example returns the year 1998.

The following example selects from the sample table hr.employees all employees who were hired after 1998:

The following example results in ambiguity, so Oracle returns UNKNOWN :

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.

Scripting on this page enhances content navigation, but does not change the content in any way.