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!

Using Case Statement in Where Clause

Purvesh KFeb 22 2011 — edited Feb 22 2011
Hello All,

I wish to conditionally use different columns for retrieving unique row. This will be dependent upon a parameter passed to the Function/Procedure.

The SQL framed looks as below:

+select *+
from Test_Table
where column_1 = <some_value>
and case when p_call_location = 'A' then column_2 like '%ABC%'
when p_call_location = 'B' then column_2 Not Like '%ABC%'
when p_call_location = 'C' then column_3 like '%EFG%'
when p_call_location = 'D' then column_3 like '%IJKL%'
END;

However, I am not sure if this works, as I am getting a Missing Right Paranthesis error. Major hinderance is the depedency on multiple columns, which would need to be referred for particular scenario.

Can somebody please help me with an example or a skeleton of how a query should be formed?

Appreciate an early reply!!!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 22 2011
Added on Feb 22 2011
3 comments
72,976 views