AdSense

網頁

2019/11/15

Oracle EXTRACT function

Oracle的EXTRACT函式能夠抽取日期時間(datetime)格式資料中的指定資訊,例如年,月,日等。

下面範例以EXTRACT抽取系統日期的各種時間資訊。

SELECT 

    SYSDATE "System datetime",
    EXTRACT(YEAR FROM SYSDATE) "Year",
    EXTRACT(MONTH FROM SYSDATE) "Month",
    EXTRACT(DAY FROM SYSDATE) "Day",
    
    EXTRACT(HOUR FROM SYSTIMESTAMP) "Hour",
    EXTRACT(MINUTE FROM SYSTIMESTAMP) "Minute",
    EXTRACT(SECOND FROM SYSTIMESTAMP) "Second"
    
FROM DUAL;

+-----------------+------+-------+-----+------+--------+----------+
| System datetime | Year | Month | Day | Hour | Minute |  Second  |
+-----------------+------+-------+-----+------+--------+----------+
| 16-NOV-19       | 2019 |    11 |  16 |   13 |     32 | 31.75173 |
+-----------------+------+-------+-----+------+--------+----------+

不過抽取時分秒資訊時,只能從SYSTIMESTAMP取得。

沒有留言:

AdSense