Consider a query like :
select * from <table_name>
where <condition1> and <condition2> and <condition3>;
Suppose Oracle executes the condition (any condition) and if not true, it does not execute the other conditions. So if I have other conditions that have logical error then it is not thrown. For example:
select count(*) from dual
where 1=0 and
'stack' = SUBSTR('stackoverflow','k', 3);
Oracle returns 0. Now remove the 1=0 condition, we get ORA-01722: invalid number
.
I know that Oracle does the cost optimization and decides the order of condition execution. So how do I override this and make it execute all the conditions so that error is thrown instead of the misleading output? Can we use hints? I am new to the hints concept, so some example would be great.
You can check condition one by one or simply using
OR
keyword to check only errors.here oracle first checks wrong condition 1=0 then its not checking another condition which also have logical error like invalid number 'a' in substr syntax.