Here some example for show all date in current/before/after month or specific month
Above is current month
select to_char( add_months(trunc(sysdate,'MM'),-1) + level - 1, 'YYYYMMDD' ) from dual connect by level <= last_day(add_months(trunc(sysdate,'MM'),-1)) - add_months(trunc(sysdate,'MM'),-1) + 1;Above is before current month
select to_char( add_months(trunc(sysdate,'MM'),1) + level - 1, 'YYYYMMDD' ) from dual connect by level <= last_day(add_months(trunc(sysdate,'MM'),1)) - add_months(trunc(sysdate,'MM'),1) + 1;Above is after current month
select to_char( trunc(sysdate,'MM') + level - 1, 'YYYYMMDD' ) from dual connect by level <= last_day(trunc(sysdate,'MM')) - trunc(sysdate,'MM') + 1;
Above is current month
select to_char( trunc(to_date('20140101','YYYYMMDD'),'MM') + level - 1, 'YYYYMMDD' ) from dual connect by level <= last_day(trunc(to_date('20140101','YYYYMMDD'),'MM')) - trunc(to_date('20140101','YYYYMMDD'),'MM') + 1;Above is specific month but you must enter date.
No comments:
Post a Comment