본문 바로가기
스터디/Oracle

[Oracle/오라클] LAST_DAY 월의 마지막 날 구하기

by 홍장 2021. 7. 11.
select substr(S1.DATE2021, 1, 6) AS MONTH2021, 
TO_CHAR(LAST_DAY(TO_DATE(S1.DATE2021)), 'DD') AS LAST_DAY
FROM (
    SELECT '20210101' AS DATE2021 FROM DUAL UNION ALL
    SELECT '20210201' AS DATE2021 FROM DUAL UNION ALL
    SELECT '20210301' AS DATE2021 FROM DUAL UNION ALL
    SELECT '20210401' AS DATE2021 FROM DUAL UNION ALL
    SELECT '20210501' AS DATE2021 FROM DUAL UNION ALL
    SELECT '20210601' AS DATE2021 FROM DUAL UNION ALL
    SELECT '20210701' AS DATE2021 FROM DUAL UNION ALL
    SELECT '20210801' AS DATE2021 FROM DUAL UNION ALL
    SELECT '20210901' AS DATE2021 FROM DUAL UNION ALL
    SELECT '20211001' AS DATE2021 FROM DUAL UNION ALL
    SELECT '20211101' AS DATE2021 FROM DUAL UNION ALL
    SELECT '20211201' AS DATE2021 FROM DUAL
) S1;

LAST_DAY() 함수는 특정월의 마지막 날을 구함