Oracle 截取时间值函数 EXTRACT
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Oracle 截取时间值函数 EXTRACT,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2501字,纯文字阅读大概需要4分钟。
内容图文
![Oracle 截取时间值函数 EXTRACT](/upload/InfoBanner/zyjiaocheng/901/a5b2fccc34bb402db31c67a99668b7ff.jpg)
Syntax
extract_datetime::=
Purpose
EXTRACT
extracts and returns the value of a specified datetime field from a datetime or interval expression. The expr
can be any expression that evaluates to a datetime or interval data type compatible with the requested field:
-
If
YEAR
orMONTH
is requested, thenexpr
must evaluate to an expression of data typeDATE
,TIMESTAMP
,TIMESTAMP
WITH
TIME
ZONE
,TIMESTAMP
WITH
LOCAL
TIME
ZONE
, orINTERVAL
YEAR
TO
MONTH
. -
If
DAY
is requested, thenexpr
must evaluate to an expression of data typeDATE
,TIMESTAMP
,TIMESTAMP
WITH
TIME
ZONE
,TIMESTAMP
WITH
LOCAL
TIME
ZONE
, orINTERVAL
DAY
TO
SECOND
. -
If
HOUR
,MINUTE
, orSECOND
is requested, thenexpr
must evaluate to an expression of data typeTIMESTAMP
,TIMESTAMP
WITH
TIME
ZONE
,TIMESTAMP
WITH
LOCAL
TIME
ZONE
, orINTERVAL
DAY
TO
SECOND
.DATE
is not valid here, because Oracle Database treats it as ANSIDATE
data type, which has no time fields. -
If
TIMEZONE_HOUR
,TIMEZONE_MINUTE
,TIMEZONE_ABBR
,TIMEZONE_REGION
, orTIMEZONE_OFFSET
is requested, thenexpr
must evaluate to an expression of data typeTIMESTAMP
WITH
TIME
ZONE
orTIMESTAMP
WITH
LOCAL
TIME
ZONE
.
EXTRACT
interprets expr
as an ANSI datetime data type. For example, EXTRACT
treats DATE
not as legacy Oracle DATE
but as ANSI DATE
, without time elements. Therefore, 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
data type.
When you specify TIMEZONE_REGION
or TIMEZONE_ABBR
(abbreviation), the value returned is a VARCHAR2
string containing the appropriate time zone region name or abbreviation. When you specify any of the other datetime fields, the value returned is an integer value of NUMBER
data type representing the datetime value 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 region names and their corresponding abbreviations, query the V$TIMEZONE_NAMES
dynamic performance view.
1. 获取当前日期中的年份
SQL> select extract(year from sysdate) as "year" from dual
2 /
year
----------
2012
2. 获取当前日期中的月份
SQL> select extract(month from sysdate) as "month" from dual
2 /
month
----------
8
3. 获取当前日期中的日
SQL> select extract(day from date'2012-12-28') as "day" from dual
2 /
day
----------
28
转载于:https://www.cnblogs.com/oradragon/archive/2012/08/30/2664674.html
内容总结
以上是互联网集市为您收集整理的Oracle 截取时间值函数 EXTRACT全部内容,希望文章能够帮你解决Oracle 截取时间值函数 EXTRACT所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。