3

I have a 2 identical databases running on Oracle 12c. They are sitting on 2 different servers.

I'm executing the following query using SQL Developer on both databases.

select *
from sla
where objectname = 'INCIDENT' and
      status in 'ACTIVE'  and
      (exists (select 1
               from classancestor
               where ancestor=sla.classstructureid and classancestor.classstructureid= '')  or
       classstructureid is null or
       classstructureid =  ''
      ) ;

I get 260 results on one of the databases and 0 results on the other. This query is generated by an ERP we are using so I cannot modify the SQL itself.

One thing I noticed is that if I remove the parentheses surrounding the exists operator, the behaviour changes.

Can someone help? Is there a precedence when using OR? Is there an Oracle patch that has an impact on how SQL statements are processed?

Thanks

10
  • the behaviour changes ... how does the behavior change? My guess is that the underlying tables are not the same. Commented Dec 29, 2017 at 13:33
  • Yes sorry, I get the same result on both databases. Both databases are identical, each table present in the SQL statement was compared thoroughly Commented Dec 29, 2017 at 13:35
  • Next question: Are both databases running the same version of Oracle? Commented Dec 29, 2017 at 13:36
  • YES Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production PL/SQL Release 12.1.0.2.0 - Production "CORE 12.1.0.2.0 Production" TNS for Linux: Version 12.1.0.2.0 - Production NLSRTL Version 12.1.0.2.0 - Production Commented Dec 29, 2017 at 13:39
  • I can't explain this, but could you update your question with the logic behind the WHERE clause? I am assuming there is some funky precedence stuff going on here, but if you write your query right, that shouldn't matter on any version or Oracle. Commented Dec 29, 2017 at 13:44

1 Answer 1

2

Ok, for now I simply reverted to Oracle 11g optimizer and solved my issue.

ALTER SYSTEM SET optimizer_features_enable='11.2.0.3';

Not my favorite solution, but it's a workaround for now.

Thanks for your help guys

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.