extract() 函数用于返回日期/时间的单独部分,比如年、月、日、小时、分钟等等。
date 参数是合法的日期表达式。unit 参数可以是下列的值:
unit 值 |
---|
microsecond |
second |
minute |
hour |
day |
week |
month |
quarter |
year |
second_microsecond |
minute_microsecond |
minute_second |
hour_microsecond |
hour_second |
hour_minute |
day_microsecond |
day_second |
day_minute |
day_hour |
year_month |
假设我们有如下的 "orders" 表:
orderid | productname | orderdate |
---|---|---|
1 | jarlsberg cheese | 2008-11-11 13:23:44.657 |
下面是 select 语句:
结果如下所示:
orderyear | ordermonth | orderday |
---|---|---|
2008 | 11 | 11 |