extract(c1 from d1)
日期/时间 d1 中,参数(c1)的值。
c1 取值:
hour 小时
minute 分钟
second 秒
DAY 日
MONTH 月
YEAR 年
d1 日期型(date)/日期时间型(timestamp)
c1 为字符型(参数)
字符
(1)使用 extract 函数提取指定日期中的年月日时分秒,如下:
SQL> select
2 extract(hour from timestamp '2022-05-07 23:24:30') 小时,
3 extract(minute from timestamp '2022-05-07 23:24:30') 分钟,
4 extract(second from timestamp '2022-05-07 23:24:30') 秒,
5 extract(DAY from timestamp '2022-05-07 23:24:30') 日,
6 extract(MONTH from timestamp '2022-05-07 23:24:30') 月,
7 extract(YEAR from timestamp '2022-05-07 23:24:30') 年
8 from dual;
小时 分钟 秒 日 月 年
---------- ---------- ---------- ---------- ---------- ----------
23 24 30 7 5 2022(2)使用 extract 函数提取当前日期中的年月日,如下:
SQL> select sysdate 当前日期,
2 extract(DAY from sysdate ) 日,
3 extract(MONTH from sysdate ) 月,
4 extract(YEAR from sysdate ) 年
5 from dual;
当前日期 日 月 年
-------------- ---------- ---------- ----------
07-5月 -22 7 5 2022(3)使用 extract 函数提取当前日期中的时分秒,如下:
SQL> select sysdate 当前日期,
2 extract(hour from CURRENT_TIMESTAMP) 小时,
3 extract(minute from CURRENT_TIMESTAMP) 分钟,
4 extract(second from CURRENT_TIMESTAMP) 秒
5 from dual;
当前日期 小时 分钟 秒
-------------- ---------- ---------- ----------
07-5月 -22 15 32 41.547