- 类别:
EXTRACT¶
Extracts the specified date or time part from a date, interval, time, or timestamp.
小技巧
要从时间戳中提取日期,请使用 TO_DATE 函数。
语法¶
实参¶
date_or_time_partThe unit of time. Must be one of the values listed in 支持的日期和时间部分 (for example,
month). The value can be a string literal or can be unquoted (for example,'month'ormonth).当
date_or_time_part为week`(或其任何变体)时,输出由 :ref:`label-week_start会话参数控制。当
date_or_time_part为dayofweek或yearofweek`(或其任何变体)时,输出由 :ref:`label-week_of_year_policy和 WEEK_START 会话参数控制。
有关更多信息(包括示例),请参阅 日历周和工作日。
date_interval_time_or_timestamp_exprA date, an interval, a time, or a timestamp, or an expression that can be evaluated to one of those data types.
返回¶
返回 NUMBER 数据类型的值。
使用说明¶
When
date_interval_time_or_timestamp_expris a year-month interval value, the supporteddate_or_time_partvalues areyearandmonth.When
date_interval_time_or_timestamp_expris a day-time interval value, the supporteddate_or_time_partvalues areday,hour,minute,second, andnanosecond.Currently, when
date_interval_time_or_timestamp_expris a DATE value, the followingdate_or_time_partvalues aren't supported:epoch_millisecondepoch_microsecondepoch_nanosecond
支持其他 日期和时间部分 (包括
epoch_second)。
示例¶
指定 year 部分,以从时间戳中提取年份:
将 EXTRACT 与 DECODE 函数和 dayofweek 部分一起使用,以返回当前星期几的全称:
备注
输出结果取决于运行查询时 SYSTIMESTAMP 函数返回的值。此外,还可以使用 DAYNAME 函数从指定日期或时间戳中提取三个字母的星期几名称。