일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- 한글
- 톰캣
- checbox
- 이클립스
- jquery
- java
- null
- SSL
- 호환성
- exception
- @RequestBody
- Oracle
- 날짜
- 스크립트
- json
- 전자정부 표준프레임워크
- DB
- HTML5
- RADIO
- 문자열
- maven
- JSTL
- html
- spring form tag
- 웹 플랫폼 설치 관리자
- php
- MYSQL
- switch
- 네이버스마트 에디터
- 오라클
- Today
- Total
개인적인 정리
ORACLE EXTRACT() 본문
오라클 EXTRACT()
EXTRACT(datetime_filed FROM expr)
datetime_field 에는
YEAR,
MONTH,
DAY,
HOUR,
MINUTE,
SECOND,
TIMEZONE_HOUR,
TIMEZONE_MINUTE,
TIMEZONE_REGION,
TIMEZONE_ABBR
이 올 수 있다.
EXTRACT extracts and returns the value of a specified datetime field from a datetime or interval expression. The expr can be any expression that evaluates to a datetime or interval data type compatible with the request filed:
- If YEAR or MONTH is requested, then expr must evaluate to an expression of data type DATE, TIMESTAMP, TIMESTAMP WITH TIME ZONE, TIMESTAMP WITH LOCAL TIME ZONE, or INTERVAL YEAR TO MONTH.
- If DAY is requested, then expr must evaluate to an expression of data type DATE, TIMESTAMP, TIMESTAMP WITH TIME ZONE, TIMESTAMP WITH LOCAL TIME ZONE, OR INTERVAL DAY TO SECOND.
- If HOUR, MINUTE, or SECOND is requested, then expr must evaluage to an expression of data type TIMESTAMP, TIMESTAMP WITH TIME ZONE, TIMESTAMP WITH LOCAL TIME ZONE, or INTERVAL DAY TO SECOND. DATE is not valid here, because Oracle Database treats it as ANSI DATE data type, which no time fields.
- If TIMEZONE_HOUR, TIMEZONE_MINUTE, TIMEZNONE_ABBR, TIMEZONE_REGION, or TIMEZONE_OFFSET is requested , then expr must evaluate to an expression of data type TIMESTAMP WITH TIME ZONE or TIMESTAPM WITH LOCAL TIME ZONE.
This function can be very useful for manipulating datetime filed values in very large tables.
월별 주문건을 구할 때 유리할 것 같다.
음..2007년 이후 입사한 사람을 구할 때도.
SQL > SELECT EXTRACT(month FROM order_date) , COUNT(order_date)
FROM orders
GROUP BY EXTRACT(month FROM order_date)
ORDER BY COUNT(order_date) DESC, EXTRACT(month FROM order_date);
SQL > SELECT EXTRACT(YEAR FROM DATE '1998-03-07') FROM DUAL ;
--> 1998
다만 이 쿼리를 TO_CHAR 로 어느정도 대체가 가능한 것 같다.
SQL > SELECT SYSDATE, EXTRACT(YEAR FROM SYSDATE), EXTRACT(MONTH FROM SYSDATE), EXTRACT(DAY FROM SYSDATE) FROM DUAL ;
--> 2020/03/30 오전 11:08:12 2020 3 30
SQL > SELECT SYSDATE, TO_CHAR(SYSDATE, 'YYYY'), TO_CHAR(SYSDATE, 'MM'), TO_CHAR(SYSDATE, 'DD') FROM DUAL ;
--> 2020/03/30 오전 11:10:01 2020 03 30
'DB > ORACLE' 카테고리의 다른 글
Oracle GROUP_ID() (0) | 2020.04.06 |
---|---|
Oracle GREATEST() (0) | 2020.03.30 |
ORACLE FLOOR() (0) | 2020.03.30 |
ORACLE FIRST() (0) | 2020.03.30 |
ORACLE EXP() (0) | 2020.03.30 |
ORACLE EMPTY_BLOB(), EMPTY_CLOB() (0) | 2020.03.30 |
ORACLE DENSE_RANK() (0) | 2020.03.26 |
ORACLE DELETEXML() (0) | 2020.03.26 |