title: ORA-01839 "date not valid for month specified" for to_date in where clause
body: <p>I have following query (<code>BOCRTNTIME - varchar e.g 2015-02-28 12:21:45, VIEW_BASE_MARIX_T - some view</code>):</p>
  
  <pre><code>select BOCRTNTIME
      from VIEW_BASE_MARIX_T
      where to_date(substr(BOCRTNTIME,1,10),'YYYY-MM-DD')
          between (to_date ('2016-01-01', 'YYYY-MM-DD'))
              and (to_date ('2016-02-01', 'YYYY-MM-DD'))
  </code></pre>
  
  <p>On executing I get error:</p>
  
  <pre><code>ORA-01839:  "date not valid for month specified"
  </code></pre>
  
  <p>I thought that there are can be incorrect data in <code>BOCRTNTIME</code>, so execute following query:</p>
  
  <pre><code>select distinct
           substr(BOCRTNTIME,1,8),
           substr(BOCRTNTIME,9,2)
    from VIEW_BASE_MARIX_T
   order by substr(BOCRTNTIME,9,2);
  </code></pre>
  
  <p>But everything looks fine: <a href="http://pastebin.com/fNjP4UAu" rel="nofollow">http://pastebin.com/fNjP4UAu</a>.
  Also following query executes without any error:</p>
  
  <pre><code>select to_date(substr(BOCRTNTIME,1,10),'YYYY-MM-DD') 
    from VIEW_BASE_MARIX_T;
  </code></pre>
  
  <p>I already tried add <code>trunc()</code> to all <code>to_date()</code> but no luck. Also I create pl/sql procedure that takes one by one item form <code>VIEW_BASE_MARIX_T</code> and convert it to date - and everything works just fine.
  Any ideas why I get error on first query?</p>
  
  <p>UPD: Query on table that used in view works fine, but in view - not</p>
  
  <p>UPD2: We have few enviroments with same products, but get error only on one</p>
  
  <p>UPD3: Issue was resolved by search non valid dates in table that used in view</p>