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!

Conversion Functions are interfering with 'or' operators??

User_M8EXOJan 5 2012 — edited Jan 5 2012
Issue with Oracle Database 11g 11.2.0.1.0

In a sql where clause, when we have a data conversion function and this function is associated to another statement with the use of an 'or' operator, the 'or' operator does not function correctly. The associated statement will not return any records even if it returns true. Below are two samples that demonstrate the issue we found.

Sample of Issue:

select m.id_number id_number,
m.mail_list_type_code mail_l_t_code,
stop_dt
from mailing_list m
where (m.stop_dt = '00000000') or (m.stop_dt > substr(to_char('20120105'),1,8));

The above where clause, (m.stop_dt = '00000000'), statement never returns data even though over 500,000 records should be returned. The (m.stop_dt > substr(to_char('20120105'),1,8) statement returns 334 records as expected. We have changed the to_char to the convert function and the same issue occurs. Basically, having a data conversion function on one side of an 'or' statement that returns data prevents the other side of the or statement from returning data even if true.

Sample when conversion function removed:

select m.id_number id_number,
m.mail_list_type_code mail_l_t_code,
stop_dt
from mailing_list m
where (m.stop_dt = '00000000') or m.stop_dt > substr('20120105',1,8);

When we remove the conversion function, 548,286, records are returned as expected.

Does anyone have an idea on what is happening. We found this issue in a lot more complex sql statement which I dumb downed to demonstrate the issue on this forum.

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 2 2012
Added on Jan 5 2012
17 comments
334 views