title: Oracle error: ORA-01839: date not valid for month specified
body: <p>OK guys, first of all, I have checked many websites about this error and, unfortunately, none of them helped me. I have the simple following query:</p>
  
  <pre><code>select * from (   
         select to_date(cal.year || cal.month || cal.day, 'yyyymmdd') as datew, 
                cal.daytype as type
         from vw_calendar cal)
  where datew &gt; sysdate;
  </code></pre>
  
  <p>When I try to execute the entire query, this error shows up:</p>
  
  <blockquote>
    <p>ORA-01839: date not valid for month specified</p>
  </blockquote>
  
  <p>If I execute only the query:</p>
  
  <pre><code>select to_date(cal.year || cal.month || cal.day, 'yyyymmdd') as datew, 
         cal.daytype as type
  from vw_calendar cal;
  </code></pre>
  
  <p>It worked absolutely fine. If you want to view the results of the query: <a href="http://pastebin.com/PV95g3ac" rel="noreferrer">http://pastebin.com/PV95g3ac</a></p>
  
  <p>I checked the days of the month like day 31 or leap year and everything seems correct. I don't know what to do anymore. My database is a Oracle 10g and I tried to execute the query on SQL Developer and PL/SQL Developer. Same error on both IDE.</p>