In the Oracle database, what does the EXTRACT() function do?

1: EXTRACT()is an SQL function used to extract a specific part from a date or time value. Its basic syntax is as follows:

EXTRACT (  field  FROM    source   )

where, fieldspecifies the part to extract sourcefrom and can be one of the following values:

  • YEAR:years
  • MONTH:month
  • DAY:Day
  • HOUR: hour (24-hour format)
  • MINUTE:minute
  • SECOND: seconds

sourceis a date or time value, which can be a column name, expression, or constant.

For example, if you have a datetimecolumn and you want to extract the year in that column, you can use the following query:

SELECT EXTRACT(YEAR FROM datetime) AS year FROM mytable;









SELECT 
DEBUG_EQUIPMENT_TREND AS 调试台设备利用率 ,
SHAKING_EQUIPMENT_TREND AS 震动台设备设备利用率 , 
STICKERS_EQUIPMENT_TREND AS 电装标贴设备利用率,
DEBUG_EQUIPMENT_FAILURERATE AS 调试台故障率,
SHAKING_EQUIPMENT_FAILURERATE AS 震动台故障率,
STICKER_EQUIPMENT_FAILURERATE AS 电装标贴故障率
FROM BRAIN.DM_EQUIPMENTUTILIZATION_TREND
WHERE EXTRACT(YEAR FROM TO_DATE(STAT_TIME, 'YYYYMM')) = '2023'     

This returns a new column yearnamed containing datetimethe year portion of each date value in the column. 

Guess you like

Origin blog.csdn.net/XikYu/article/details/129438357