Where The Streets Have No Name

구간에 존재하는 날짜 구하기 본문

Developement/DataBase

구간에 존재하는 날짜 구하기

highheat 2006. 11. 8. 15:41
현재달의 날짜전부
select trunc(sysdate,'month') + n
from(select rownum-1 n
        from dual
        connect by level <= to_number(to_char(last_day(sysdate),'dd')))

오늘날짜부터 이달의 1일까지

select trunc(sysdate,'month') + n
from(select rownum-1 n
         from dual
         connect by level <= to_number(to_char(sysdate,'dd')))

내일부터 이달말일까지
select trunc(sysdate,'month') + n
from(select rownum-1 n
        from dual
        connect by level <= to_number(to_char(last_day(sysdate),'dd')))
minus
select trunc(sysdate,'month') + n
from(select rownum-1 n
        from dual
        connect by level <= to_number(to_char(sysdate,'dd')))


이번달부터 정해진 기간까지
select to_char(add_months(sysdate,n),'yyyymm')
from
(select rownum-1 as n
 from dual
 connect by  level <= :p_range)

시작월부터 정해진 기간의 월을 구함
select to_char(add_months(to_date(:p_start_month,'yyyymm'),level-1),'yyyymm') as yyyymm      
from dual
connect by level <= :p_month_range

시작월부터 종료월의 월을 구함
select to_char(add_months(to_date(:p_start_month,'yyyymm'),level-1),'yyyymm') as yyyymm     
from dual
connect by level <= months_between(to_date(:p_end_month,'yyyymm'),to_date(:p_start_month,'yyyymm')) + 1