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 32 33 34 35
| with sr as
(
select add_months(trunc(sysdate, 'yyyy'), level-1) as dt
from dual
connect by level <= 12
)
select dt
, case
when sign(to_number(to_char(dt -interval '1' month ,'mm')-8 )) = -1
then to_date('3112'||to_char((dt - interval '1' year),'yyyy'),'ddmmyyyy')
when sign(to_number(to_char(dt -interval '1' month ,'mm')-8 )) = 0
then to_date('3112'||to_char((dt - interval '1' year),'yyyy'),'ddmmyyyy')
else to_date('3112'||to_char((dt),'YYYY'),'ddmmyyyy')
end as exp1
, case
when extract(month from dt) between 2 and 9
then trunc(dt, 'yyyy')-1
else add_months(trunc(dt, 'yyyy')-1, 12)
end as exp2
from sr;
DT EXP1 EXP2
---------- ---------- ----------
01/01/2011 31/12/2011 31/12/2011
01/02/2011 31/12/2010 31/12/2010
01/03/2011 31/12/2010 31/12/2010
01/04/2011 31/12/2010 31/12/2010
01/05/2011 31/12/2010 31/12/2010
01/06/2011 31/12/2010 31/12/2010
01/07/2011 31/12/2010 31/12/2010
01/08/2011 31/12/2010 31/12/2010
01/09/2011 31/12/2010 31/12/2010
01/10/2011 31/12/2011 31/12/2011
01/11/2011 31/12/2011 31/12/2011
01/12/2011 31/12/2011 31/12/2011 |