advertisements
_____________________________________________________________________________________________________________________
The
input for this query is the first date of the year. It will display the calendar.
Interesting one.. Try this J
Undefine inpdate
select ' MONTH YYYY WK Mo
Tu We Th Fr Sa Su' Calender from dual
union
select
a.w1||listagg(decode(a.dt1, '01',LPAD('01',to_number (decode(a.d1,'1','8',a.d1))*3-4,'
') ,a.dt1),' ') WITHIN GROUP (ORDER BY a.w1) Calender
from (
Select
to_char(trunc(to_date('&&inpdate','dd/mm/yyyy'),'mm')+rownum-1,'d') D1,
to_char(trunc(to_date('&&inpdate','dd/mm/yyyy'),'mm')+rownum-1,'dd')
DT1,
to_char(trunc(to_date('&&inpdate','dd/mm/yyyy'),'mm')+rownum-1,'MM-MON IYYY
IW ') w1
from dba_tables
where
add_months(trunc(to_date('&&inpdate','dd/mm/YYYY'),'YYYY'),12) >trunc(to_date('&&inpdate','dd/mm/YYYY'),'YYYY')+rownum-1)
a
group by a.w1;
Sample Calender for 2014
SQL>
select ' MONTH YYYY WK Mo
Tu We Th Fr Sa Su' Calender from dual
2
union
3
select
a.w1||listagg(decode(a.dt1,'01',LPAD('01',to_number(decode(a.d1,'1','8',a.d1))*3-4,'
'),a.dt1),' ') WITHIN GROUP (ORDER BY a.w1) Calender
4 from
(
5
Select
to_char(trunc(to_date('&&inpdate','dd/mm/yyyy'),'mm')+rownum-1,'d') D1,
6
to_char(trunc(to_date('&&inpdate','dd/mm/yyyy'),'mm')+rownum-1,'dd')
DT1,
7
to_char(trunc(to_date('&&inpdate','dd/mm/yyyy'),'mm')+rownum-1,'MM-MON IYYY
IW ') w1
8 from
dba_tables
9
where
add_months(trunc(to_date('&&inpdate','dd/mm/YYYY'),'YYYY'),12)> trunc(to_date('&&inpdate','dd/mm/YYYY'),'YYYY')+rownum-1)
a
10
group by a.w1;
Enter
value for inpdate: 01/01/2014
old 5: Select
to_char(trunc(to_date('&&inpdate','dd/mm/yyyy'),'mm')+rownum-1,'d') D1,
new 5: Select
to_char(trunc(to_date('01/01/2014','dd/mm/yyyy'),'mm')+rownum-1,'d') D1,
old 6:
to_char(trunc(to_date('&&inpdate','dd/mm/yyyy'),'mm')+rownum-1,'dd')
DT1,
new 6:
to_char(trunc(to_date('01/01/2014','dd/mm/yyyy'),'mm')+rownum-1,'dd')
DT1,
old 7:
to_char(trunc(to_date('&&inpdate','dd/mm/yyyy'),'mm')+rownum-1,'MM-MON IYYY IW ') w1
new 7:
to_char(trunc(to_date('01/01/2014','dd/mm/yyyy'),'mm')+rownum-1,'MM-MON IYYY
IW ') w1
old 9: where
add_months(trunc(to_date('&&inpdate','dd/mm/YYYY'),'YYYY'),12)> trunc(to_date('&&inpdate','dd/mm/YYYY'),'YYYY')+rownum-1)
a
new 9: where
add_months(trunc(to_date('01/01/2014','dd/mm/YYYY'),'YYYY'),12)> trunc(to_date('01/01/2014','dd/mm/YYYY'),'YYYY')+rownum-1)
a
CALENDER
--------------------------------------------
MONTH
YYYY WK Mo Tu We Th Fr Sa Su
01-JAN 2014
01 01 02 03 04 05
01-JAN 2014
02 06 07 08 09 10 11 12
01-JAN 2014
03 13 14 15 16 17 18 19
01-JAN 2014
04 20 21 22 23 24 25 26
01-JAN 2014
05 27 28 29 30 31
02-FEB 2014
05 01 02
02-FEB 2014
06 03 04 05 06 07 08 09
02-FEB 2014
07 10 11 12 13 14 15 16
02-FEB 2014
08 17 18 19 20 21 22 23
02-FEB 2014
09 24 25 26 27 28
03-MAR 2014
09 01 02
03-MAR 2014
10 03 04 05 06 07 08 09
03-MAR 2014
11 10 11 12 13 14 15 16
03-MAR 2014
12 17 18 19 20 21 22 23
03-MAR 2014
13 24 25 26 27 28 29 30
03-MAR 2014
14 31
04-APR 2014
14 01 02 03 04 05 06
04-APR 2014
15 07 08 09 10 11 12 13
04-APR 2014
16 14 15 16 17 18 19 20
04-APR 2014
17 21 22 23 24 25 26 27
04-APR 2014
18 28 29 30
05-MAY 2014
18 01 02 03 04
05-MAY 2014
19 05 06 07 08 09 10 11
05-MAY 2014
20 12 13 14 15 16 17 18
05-MAY 2014
21 19 20 21 22 23 24 25
05-MAY 2014
22 26 27 28 29 30 31
06-JUN 2014
22 01
06-JUN 2014
23 02 03 04 05 06 07 08
06-JUN 2014
24 09 10 11 12 13 14 15
06-JUN 2014
25 16 17 18 19 20 21 22
06-JUN 2014
26 23 24 25 26 27 28 29
06-JUN 2014
27 30
07-JUL 2014
27 01 02 03 04 05 06
07-JUL 2014
28 07 08 09 10 11 12 13
07-JUL 2014
29 14 15 16 17 18 19 20
07-JUL 2014
30 21 22 23 24 25 26 27
07-JUL 2014
31 28 29 30 31
08-AUG 2014
31 01 02 03
08-AUG 2014
32 04 05 06 07 08 09 10
08-AUG 2014
33 11 12 13 14 15 16 17
08-AUG 2014
34 18 19 20 21 22 23 24
08-AUG 2014
35 25 26 27 28 29 30 31
09-SEP 2014
36 01 02 03 04 05 06 07
09-SEP 2014
37 08 09 10 11 12 13 14
09-SEP 2014
38 15 16 17 18 19 20 21
09-SEP 2014
39 22 23 24 25 26 27 28
09-SEP 2014 40 29 30
10-OCT 2014
40 01 02 03 04 05
10-OCT 2014
41 06 07 08 09 10 11 12
10-OCT 2014
42 13 14 15 16 17 18 19
10-OCT 2014
43 20 21 22 23 24 25 26
10-OCT 2014
44 27 28 29 30 31
11-NOV 2014
44 01 02
11-NOV 2014
45 03 04 05 06 07 08 09
11-NOV 2014
46 10 11 12 13 14 15 16
11-NOV 2014
47 17 18 19 20 21 22 23
11-NOV 2014
48 24 25 26 27 28 29 30
12-DEC 2014
49 01 02 03 04 05 06 07
12-DEC 2014
50 08 09 10 11 12 13 14
12-DEC 2014
51 15 16 17 18 19 20 21
12-DEC 2014
52 22 23 24 25 26 27 28
12-DEC 2015
01 29 30 31
_____________________________________________________________________________________________________________________
0 comments:
Post a Comment