Oracle EXTRACT (datetime)
Oracle datetime extract
2023-09-14 09:02:14 时间
EXTRACT (datetime)
Syntax
extract_datetime::=
![Description of extract_datetime.gif follows Description of extract_datetime.gif follows](http://docs.oracle.com/cd/B19306_01/server.102/b14200/img/extract_datetime.gif)
Description of the illustration extract_datetime.gif
EXTRACT extracts and returns the value of a specified datetime field from a datetime or interval value expression. When you extract a TIMEZONE_REGION orTIMEZONE_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. 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 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 aDATE value. Likewise, you can extract TIMEZONE_HOUR and TIMEZONE_MINUTE only from the TIMESTAMP WITH TIME ZONE datatype. See Also:
The following example returns from the oe.orders table the number of orders placed in each month:
![Description of extract_datetime.gif follows Description of extract_datetime.gif follows](http://docs.oracle.com/cd/B19306_01/server.102/b14200/img/extract_datetime.gif)
Description of the illustration extract_datetime.gif
EXTRACT extracts and returns the value of a specified datetime field from a datetime or interval value expression. When you extract a TIMEZONE_REGION orTIMEZONE_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. 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 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 aDATE value. Likewise, you can extract TIMEZONE_HOUR and TIMEZONE_MINUTE only from the TIMESTAMP WITH TIME ZONE datatype. See Also:
The following example returns from the oe.orders table the number of orders placed in each month:
SELECT EXTRACT(month FROM order_date) "Month", COUNT(order_date) "No. of Orders" FROM orders GROUP BY EXTRACT(month FROM order_date) ORDER BY "No. of Orders" DESC; Month No. of Orders ---------- ------------- 11 15 7 14 6 14 3 11 5 10 10 6 12 4 12 rows selected.The following example returns the year 1998.
SELECT EXTRACT(YEAR FROM DATE 1998-03-07) FROM DUAL; EXTRACT(YEARFROMDATE1998-03-07) --------------------------------- 1998The following example selects from the sample table hr.employees all employees who were hired after 1998:
SELECT last_name, employee_id, hire_date FROM employees WHERE EXTRACT(YEAR FROM TO_DATE(hire_date, DD-MON-RR)) 1998 ORDER BY hire_date;
The following example results in ambiguity, so Oracle returns UNKNOWN:SELECT EXTRACT(TIMEZONE_REGION FROM TIMESTAMP 1999-01-01 10:00:00 -08:00) FROM DUAL; EXTRACT(TIMEZONE_REGIONFROMTIMESTAMP1999-01-0110:00:00-08:00) ---------------------------------------------------------------- UNKNOWNThe 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.
Oracle之:Function :getdate() create or replace function getdate(sp_date varchar) return date is Result date; begin if LENGTH(sp_date) =10 then Result:=to_date(s...
Oracle DB Time是Oracle数据库在时间维度上剖析性能的一个重要指标,通过逐级分解该指标,定位到浪费资源或者资源争用的首要事件上,从而通过减少等待以及最小化每个请求的使用资源来达到优化的目的。
相关文章
- Oracle-PLSQL Developer使用笔记
- 【性能优化】CBO,RBO在ORACLE中的应用
- 【oracle】静默安装oracle软件和数据库之二
- oracle导出dmp文件的2种方法
- Oracle监听服务启动失败案例
- 使用plsql连接别人的oracle(转)
- 配置vnc远程连接Linux和unix服务器图形界面安装Oracle
- Oracle EXTRACT (datetime)
- Oracle 数据库 恢复
- Oracle与Sql Server复制表结构及数据
- Oracle中会话与事务有什么区别?
- sql中datetime日期类型字段比较(mysql&oracle)
- Oracle建立表空间和用户
- Windows平台修改oracle主机的主机名或IP地址后出现的问题处理
- Oracle 数据库用户创建、重启、导入导出
- 01、Oracle基本select语句