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!

Need help in query involving subquery and dates..

547625May 8 2007 — edited May 31 2007
Hi,

I have a query like this.

select 'x'
from (select
to_date(column1) A1,
to_date(Column2) A2
from tab1
where column3 = 'Tree'
and column4 = 111)
where :1 between A1 and A2;

In the table tab1, I have values in the columns column1 and column2 which are date compatible (e.g. '01-jan-2000') as well as date non-compatible (e.g 'a12bn'). But for the rows that have values in column3 = 'Tree', the values in column1 and column2 are always date compatible.

Right now, I have no indexes on this table.

Now is it possible that when I run this query, oracle will also pick those rows, in which the values of column1 and column2 are non-date compatible and throw an incorrect date format error while applying to_date function on column1 and column2 of these rows?

I am facing this issue, in which this query returns with an incorrect date format error. Some people suggest that the inner query gets combined with the main, which causes (possibly) the date format error to be thrown. Is that true?

Though when I create an index on column3 and column4, it starts working fine and returns correct results.
What I expect is even without the index I should not see any error as the inner query should work independent of the outer query and filter out all those rows for which column3 = 'Tree' and column4 = 111. As these rows have date compatible column1 and column2, to_date on these columns should go fine.
Please advise.
Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 28 2007
Added on May 8 2007
16 comments
1,529 views