Sql代碼
EXTRACT extracts and returns the value of a specified datetime field from a datetime or interval value expression
The field you are extracting must be a field of the datetime_value_expr or interval_value_expr
eg
?SELECT EXTRACT(YEAR FROM SYSDATE) FROM DUAL; return Current Year
?SELECT EXTRACT(MONTH FROM SYSDATE) FROM DUAL; return Current Month
?SELECT EXTRACT(DAY FROM SYSDATE) FROM DUAL; return Current Day
?SELECT EXTRACT(HOUR FROM SYSDATE) FROM DUAL;Error
Correct:SELECT EXTRACT(HOUR FROM TIMESTAMP
?SELECT EXTRACT(MINUTE FROM SYSDATE) FROM DUAL;Error
Correct:SELECT EXTRACT(MINUTE FROM TIMESTAMP
以上是EXTRACT()函數的使用說明
EXTRACT(YEAR FROM SYSDATE)中FROM 的下一個參數是日期類型的時候可以抽取年月日
這裡要注意
比如(MINUTE FROM TIMESTAMP to_date(to_char(日期類型
如果真要從日期類型的字段中抽取時\分部分用to_char() 函數就可以了
From:http://tw.wingwit.com/Article/program/Oracle/201311/18616.html