Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

date conversion in where clause

487397May 9 2008 — edited May 9 2008
I have some legacy data where one of the fields is a five digit number representing a date in 'rrddd' format. I need a query with a date condition on this column.

Simply put, I need a query like this:

select * from table
where to_date(lpad(status_date, 5, '0'), 'rrddd') >= sysdate - 10;

However, there's bad source data (of course there is!) which raises an ORA-1848 date conversion error.

So, I wrote a function to validate the dates first and embedded it into a subquery:

select v.* from
(select * from table
where is_valid_rrddd_date(status_date) = 'Y') v
where to_date(lpad(v.status_date, 5, '0'), 'rrddd') >= sysdate - 10;

The problem is the query is not sufficiently complex that the optimizer doesn't just roll-up the subquery and evaluate both conditions at the same time (or so I theorize), and it still raises the 1848 exception.

Is there any kind of Oracle hint I can use to force the optimizer to evaluate the subquery first?

Or is there an alternate approach?

Thanx in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 6 2008
Added on May 9 2008
1 comment
646 views