SELECT TO_CHAR(TO_DATE('20200107','YYYYMMDD'), 'D')
FROM DUAL
요일 1(일)~7(토)이 나오는 이걸 이용하면
아래와 같이 휴일정보만 직접 입력해서 영업일을 뽑아낼 수 있다.
SELECT COUNT(A.DT)
FROM ( SELECT TO_CHAR (SDT + LEVEL - 1, 'YYYYMMDD') DT,
TO_CHAR (SDT + LEVEL - 1, 'D') D
FROM (SELECT TO_DATE ('20200101', 'YYYYMMDD') SDT,
TO_DATE ('20201130', 'YYYYMMDD') EDT
FROM DUAL)
CONNECT BY LEVEL <= EDT - SDT + 1) A
LEFT OUTER JOIN (
SELECT '20200301' DT, '3.1절' CMT FROM DUAL -- 휴일정보(테이블)
UNION ALL
SELECT '20200101' DT, '신정' CMT FROM DUAL -- 휴일정보(테이블)
UNION ALL
SELECT '20200124' DT, '구정' CMT FROM DUAL -- 휴일정보(테이블)
UNION ALL
SELECT '20200127' DT, '신정대휴' CMT FROM DUAL -- 휴일정보(테이블)
UNION ALL
SELECT '20200415' DT, '총선' CMT FROM DUAL -- 휴일정보(테이블)
UNION ALL
SELECT '20200430' DT, '석탄일' CMT FROM DUAL -- 휴일정보(테이블)
UNION ALL
SELECT '20200505' DT, '키즈' CMT FROM DUAL -- 휴일정보(테이블)
UNION ALL
SELECT '20200815' DT, '광복절' CMT FROM DUAL -- 휴일정보(테이블)
UNION ALL
SELECT '20200817' DT, '대휴' CMT FROM DUAL -- 휴일정보(테이블)
UNION ALL
SELECT '20200930' DT, '추석' CMT FROM DUAL -- 휴일정보(테이블)
UNION ALL
SELECT '20201001' DT, '추석' CMT FROM DUAL -- 휴일정보(테이블)
UNION ALL
SELECT '20201002' DT, '추석' CMT FROM DUAL -- 휴일정보(테이블)
UNION ALL
SELECT '20201009' DT, '한글날' CMT FROM DUAL -- 휴일정보(테이블)
UNION ALL
SELECT '20201225' DT, '성탄절' CMT FROM DUAL -- 휴일정보(테이블)
) B
ON A.DT = B.DT
WHERE 2=2
AND A.D NOT IN ('1', '7') -- 토/일요일 제외
AND B.DT IS NULL
ORDER BY 1