title: Oracle date as fraction of month
body: <p>I would like to get a table of months between two dates with a fraction of each month that the two dates cover.</p>
  
  <p>For example with a start date of 15/01/2017 and end date of 01/03/2017 it would output:</p>
  
  <pre><code>01/2017 : 0.5483..
  02/2017 : 1
  03/2017: 0.0322..
  </code></pre>
  
  <p>where for January and March the calculations are 17/31 and 1/31 respectively. I currently have the query: </p>
  
  <pre><code>WITH dates_between as (SELECT ADD_MONTHS(TRUNC(TO_DATE(:givenStartDate,'dd/mm/yyyy'), 'MON'), ROWNUM - 1) date_out
                      FROM   DUAL
                      CONNECT BY ADD_MONTHS(TRUNC(TO_DATE(:givenStartDate,'dd/mm/yyyy'), 'MON'), ROWNUM - 1)
                          &lt;= TRUNC(TO_DATE(:givenEndDate,'dd/mm/yyyy'), 'MON')
  )
  
  select * from dates_between
  </code></pre>
  
  <p>This outputs each month between two dates and formats it to the start of the month. I just need another column to give me the fraction the start and end dates cover. I'm not sure of a way to do this without it getting messy.</p>