title: connected by months
body: <p>Ok, I'm new using this <code>connect by</code> thing. But its always quite useful. I have this small problem you guys might be able to help me...</p>
  
  <p>Given start month (say <code>to_char(sysdate,'YYYYMM')</code>) and end month (say, <code>to_char(add_months(sysdate, 6),'YYYYMM')</code>), want to get the list of months in between, in the same format.</p>
  
  <p>Well, I want to use this into a partitions automation script. My best shot so far (pretty pitiful) yields invalid months e.g.'201034'... (and yea, I know, incredibly inefficient)</p>
  
  <p>Follows the code:</p>
  
  <pre><code>SELECT id
  from
      (select to_char(add_months(sysdate, 6),'YYYYMM') as tn_end, to_char(sysdate,'YYYYMM') as tn_start from dual) tabla,
      (select * from
          (Select Level as Id from dual connect by Level &lt;= (Select to_char(add_months(sysdate, 1),'YYYYMM')from dual)) where id &gt; to_char(sysdate,'YYYYMM')) t
  Where 
      t.Id between tabla.tn_start and tabla.tn_end
  </code></pre>
  
  <p>how do I do to make this query return only valid months? Any tips?</p>
  
  <p>cheers mates,</p>
  
  <p>f.</p>