Home > database >  How to intercept to each month
How to intercept to each month

Time:10-05

If there are two parameters startDate (start time), endDate (end time)
Once passed two arguments, how SQL can detect each month,
The startDate is 20150106, for example, endDate is 20150827,
How to query data to output per month, which is 1,2,3,4,5,6,7,8 this month, I want to take a month to do calculating, could you tell me how to do this?

CodePudding user response:

Select to_date (' 201501 ', 'yyyymm') + the from dual rownum - 1
Connect by rownum & lt;=months_between (to_date (' 201508 ', 'yyyymm'), to_date (' 201501 ', 'yyyymm')) + 1

CodePudding user response:

The select add_months (to_date (' 201501 ', 'yyyymm'), rownum - 1) from dual
Connect by rownum & lt;=months_between (to_date (' 201508 ', 'yyyymm'), to_date (' 201501 ', 'yyyymm')) + 1

CodePudding user response:

SQL> Select the extract (the month from to_date (' 201501 ', 'yyyymm')) + level 1
2 the from dual
3 connect by level & lt;=months_between (to_date (' 201508 ', 'yyyymm'), to_date (' 201501 ', 'yyyymm')) + 1;

EXTRACT (MONTHFROMTO_DATE (' 201501 ', 'YYYYMM')) + LEVEL 1
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1
2
3
4
5
6
7
8
  • Related