I'll guess that ol.value contains lots of data, data other than stuff in the format dd-mm-yyyy hh24:mi
eg: you have that "funky data model whereby we just store everything in a string"
And you think predicates are evaluated in some precise order (they are not)
likely you have to:
case when <some condidition is true> then to_date( ol.value, .... ) end
that is, check the condition that tells you "ol.value is a date hiding in a silly string" before applying to_date to it.
ops$tkyte@ORA920> create table t ( typ varchar2(1), val varchar2(30) );
Table created.
ops$tkyte@ORA920> insert into t values ( 'N', 12 );
1 row created.
ops$tkyte@ORA920> insert into t values ( 'D', '01-01-2007 00:00' );
1 row created.
ops$tkyte@ORA920>
ops$tkyte@ORA920> select * from t where typ='D' and to_date( val, 'fxDD-MM-YYYY HH24:MI' )< sysdate;
select * from t where typ='D' and to_date( val, 'fxDD-MM-YYYY HH24:MI' )< sysdate
*
ERROR at line 1:
ORA-01840: input value not long enough for date format
ops$tkyte@ORA920> select * from t where to_date( val, 'fxDD-MM-YYYY HH24:MI' )< sysdate and typ='D';
T VAL
- ------------------------------
D 01-01-2007 00:00
ops$tkyte@ORA920> select * from t where typ='D' and case when typ='D' then to_date( val, 'fxDD-MM-YYYY HH24:MI' ) end < sysdate;
T VAL
- ------------------------------
D 01-01-2007 00:00
ops$tkyte@ORA920> select * from t where case when typ='D' then to_date( val, 'fxDD-MM-YYYY HH24:MI' ) end < sysdate and typ='D';
T VAL
- ------------------------------
D 01-01-2007 00:00