このようなもの:
SQL> create table person (PersonnelId primary key, AbsenceReason , AbsenceFrom , AbsenceTo)
2 as
3 select 4, 'Holiday', '2/12/2012', '10/12/2012'
4 from dual;
Table created.
to_date('12-2012', 'mm-yyyy')
該当する月/年を設定するだけです:
SQL> with mon as (select d
2 from (select to_date('12-2012', 'mm-yyyy') + rownum - 1 d
3 from dual
4 connect by level <= 31)
5 where trunc(d, 'mm') = to_date('12-2012', 'mm-yyyy'))
6 select personnelId, m.d,
7 case
8 when m.d between p.AbsenceFrom and p.AbsenceTo then 'Holiday'
9 else 'Available'
10 end absent
11 from mon m
12 cross join person p
13 order by 1, 2;
PERSONNELID D ABSENT
----------- ---------- ---------
4 01/12/2012 Available
4 02/12/2012 Holiday
4 03/12/2012 Holiday
4 04/12/2012 Holiday
4 05/12/2012 Holiday
4 06/12/2012 Holiday
4 07/12/2012 Holiday
4 08/12/2012 Holiday
4 09/12/2012 Holiday
4 10/12/2012 Holiday
4 11/12/2012 Available
4 12/12/2012 Available
4 13/12/2012 Available
4 14/12/2012 Available
4 15/12/2012 Available
4 16/12/2012 Available
4 17/12/2012 Available
4 18/12/2012 Available
4 19/12/2012 Available
4 20/12/2012 Available
4 21/12/2012 Available
4 22/12/2012 Available
4 23/12/2012 Available
4 24/12/2012 Available
4 25/12/2012 Available
4 26/12/2012 Available
4 27/12/2012 Available
4 28/12/2012 Available
4 29/12/2012 Available
4 30/12/2012 Available
4 31/12/2012 Available