From: anil4yesu on


The following SQL works well without the last line, once I add the
last line, I get ORA-01858.
I am not sure why it works in the SELECT but not in the WHERE clause.

We have Oracle 9.2.0.7.

select msg, source, msg_type, svr_cd,
to_date(substr(msg,instr(msg,'Eff Dt:') + 8,10), 'mm/dd/yyyy')
from hotlist
where fnctn = 'ROUTE'
and source = 'SRF Data'
and (sysdate - 30) > to_date(substr(msg,instr(msg,'Eff Dt:') + 8,10),
'mm/dd/yyyy')

Any suggestions/thoughts are appreciated

Thanks

From: Maxim Demenko on
anil4yesu(a)gmail.com schrieb:
>
> The following SQL works well without the last line, once I add the
> last line, I get ORA-01858.
> I am not sure why it works in the SELECT but not in the WHERE clause.
>
> We have Oracle 9.2.0.7.
>
> select msg, source, msg_type, svr_cd,
> to_date(substr(msg,instr(msg,'Eff Dt:') + 8,10), 'mm/dd/yyyy')
> from hotlist
> where fnctn = 'ROUTE'
> and source = 'SRF Data'
> and (sysdate - 30) > to_date(substr(msg,instr(msg,'Eff Dt:') + 8,10),
> 'mm/dd/yyyy')
>
> Any suggestions/thoughts are appreciated
>
> Thanks
>

Probably because there are values which don't result in proper date
format 'mm/dd/yyyy'.
You can try one of both approaches:

select /*+ ORDERED_PREDICATES */ msg, source, msg_type, svr_cd,
to_date(substr(msg,instr(msg,'Eff Dt:') + 8,10), 'mm/dd/yyyy')
from hotlist
where fnctn = 'ROUTE'
and source = 'SRF Data'
and (sysdate - 30) > to_date(substr(msg,instr(msg,'Eff Dt:') +
8,10),'mm/dd/yyyy')

or

select /*+ NO_MERGE */ msg, source, msg_type, svr_cd,
to_date(substr(msg,instr(msg,'Eff Dt:') + 8,10), 'mm/dd/yyyy')
from
(select * from
hotlist
where fnctn = 'ROUTE'
and source = 'SRF Data')
where (sysdate - 30) > to_date(substr(msg,instr(msg,'Eff Dt:') +
8,10),'mm/dd/yyyy')


Best regards

Maxim