当前位置: 首页 > 工具软件 > Extract > 使用案例 >

Oracle EXTRACT()函数

祁增
2023-12-01

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. For example, you can extract only YEAR, MONTH, and DAY from a DATE value. Likewise, you can extract TIMEZONE_HOUR and TIMEZONE_MINUTE only from the TIMESTAMP WITH TIME ZONE datatype.
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 '2005-10-10 10:10:10') FROM DUAL;
  • SELECT EXTRACT(MINUTE FROM SYSDATE) FROM DUAL;Error
  • Correct:SELECT EXTRACT(MINUTE FROM TIMESTAMP '2005-10-10 10:10:10') FROM DUAL;
 类似资料: