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!

Query with the conditional where

tironeAug 18 2020 — edited Aug 21 2020

hi, I need help to write a query (no pl/sql) with the conditional where clause.
The condition is driven by the content of the MY_VAR variable.

In case MY_VAR contains a value other than 'ALL'
The query should extract from a table tbl1 all the records in which the value of the X field is in a list extracted with a subquery

If the content of the MY_VAR is equal to 'ALL' all the records should be extracted (no where condition)

something like: (bad syntax)
select *
from tbl1 t1
CASE
     when my_var <> 'ALL' then where t1.x in (select t2.x fro tbl2 t2)
     else ''
END

Thanks in advance
regards
saverio

This post has been answered by Frank Kulash on Aug 18 2020
Jump to Answer
Comments
Post Details
Added on Aug 18 2020
4 comments
2,105 views