parameter - cond

Hi
Is it possible to have a conditional parameter on a query
eg
--:p_para1 -- enter either 1 or 2
--:p_product
--:p_company

select
t1.*
from mytable t1
where
(if :p_para1 = 1 then t1.product = :p_product
else
t1.company = :p_company)

Regards
PHIL SawyerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
Maybe an OR?

(:p_para1 = 1 and t1.product = :p_product)
or
(t1.company = :p_company)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sdstuberCommented:
OR is correct, but needs to be more explicit (I think, not entirely sure on what you're trying to if/else in your pseudocode)

select
t1.*
from mytable t1
where
( :p_para1 = 1 and t1.product = :p_product)
or
(:p_para1 = 2 and t1.company = :p_company)

Open in new window



alternately, but this second version is likely to be less useful with indexes

select
t1.*
from mytable t1
where
( :p_para1 = 1 and t1.product = :p_product)
or
(:p_para1 != 1 and t1.company = :p_company)

Open in new window

0
PHIL SawyerAuthor Commented:
Thanks
0
sdstuberCommented:
hmm, I was maybe a little too late.

Are you sure the accepted answer does what you wan it to?
0
sdstuberCommented:
philipsivyer,


for example - let's say you have row of data like this...

PRODUCT= your_product
COMPANY = your_company


Then I pass in the following parameters:

p_para1 = 1
p_product = my_product
p_company = your_company

I assume you would want to exclude that row.  The answer you accepted does NOT, it would return that row which doesn't seem correct
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.