Skip to Main Content
  • Questions
  • Where clause mix of AND and OR with()

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, saeedeh.

Asked: November 06, 2017 - 4:12 pm UTC

Last updated: November 09, 2017 - 11:49 am UTC

Version: 11.1

Viewed 1000+ times

You Asked

Hello,
I need to mix and or in where cluse:
like: and con1 and (con2 or con3 or con4)...

t_where := t_where || ' and a.field1 = ''' ||
l_1 || '''' || ' ( ' || 'a.field2 = ''' ||
l_2 || '''' || ' or ' || ... || ' ) ' ;

sth llike this, but I have error.
could you give me a sample?
Thanks

and Connor said...

select count(*)
from all_objects
where owner = 'SYSTEM'
and ( object_id = 123 or created > sysdate )
and ( status = 'VALID' or DUPLICATED = 'YES' or SHARDED = 'YES' )


etc

"AND" will take priority over "OR" unless brackets are used.

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

SQL

The Oracle documentation contains a complete SQL reference.