Question

I have build a view with following query.

SELECT TRUNC(sysdate - (365), 'YYYY') + (level-1) AS the_day
  FROM dual
    CONNECT BY level <= to_number(TO_CHAR(last_day(add_months(TRUNC(sysdate, 'YYYY'),11)), 'DDD'))

above query return output like below.

THE_DAY
---------
01-JAN-11
02-JAN-11
03-JAN-11
04-JAN-11
05-JAN-11
06-JAN-11
07-JAN-11
08-JAN-11
09-JAN-11
10-JAN-11
11-JAN-11

...

20-DEC-11
21-DEC-11
22-DEC-11
23-DEC-11
24-DEC-11
25-DEC-11
26-DEC-11
27-DEC-11
28-DEC-11
29-DEC-11
30-DEC-11
31-DEC-11
01-JAN-12

This is January of 2012. so i need to remove all days from 01-JAN-11 to 31-JAN-11 from above output and add all days from 01-JAN-12 to 31-JAN-12 to output.

how can i do this ? how should i modify my query for get result like below.

THE_DAY
---------
01-FEB-11
02-FEB-11
03-FEB-11
04-FEB-11
05-FEB-11
06-FEB-11
07-FEB-11
08-FEB-11
09-FEB-11
10-FEB-11
11-FEB-11

...

20-DEC-11
21-DEC-11
22-DEC-11
23-DEC-11
24-DEC-11
25-DEC-11

...

01-JAN-12
02-JAN-12
03-JAN-12
04-JAN-12
05-JAN-12
06-JAN-12
07-JAN-12
08-JAN-12
09-JAN-12
10-JAN-12
11-JAN-12
12-JAN-12
...
30-JAN-12
31-JAN-12
Was it helpful?

Solution

SELECT add_months(TRUNC(sysdate - (365), 'YYYY'),to_number(to_char(sysdate,'mm'))) + (level - 1) AS the_day
  FROM dual
CONNECT BY level <=
           to_number(TO_CHAR(last_day(add_months(TRUNC(sysdate, 'YYYY'), 11)),
                             'DDD'))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top