Home » SQL & PL/SQL » SQL & PL/SQL » Sql qyery
Sql qyery [message #262522] Mon, 27 August 2007 06:23 Go to next message
dimis283
Messages: 38
Registered: July 2007
Location: greece
Member
I have this query
select a,b from my table where c=:some1 or c=:some2

I want to ignore
c=:some1 and c=:some2 if some1 or some2 is null, meaning that for example if :some1 is null the statement will be
select a,b from my table where c=:some2 
.
Is that possible?
Thank you
Dimis

[Updated on: Mon, 27 August 2007 06:27]

Report message to a moderator

Re: Sql qyery [message #262523 is a reply to message #262522] Mon, 27 August 2007 06:28 Go to previous messageGo to next message
pablolee
Messages: 2836
Registered: May 2007
Location: Scotland
Senior Member
You can use decode in the operand:
where c=decode(:some1, NULL, c, :some1)
Re: Sql qyery [message #262531 is a reply to message #262522] Mon, 27 August 2007 07:26 Go to previous messageGo to next message
Michel Cadot
Messages: 64152
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
There is nothing to do.
It is already the case.
if :some1 is null then "c=:some1" is never true and the condition "c=:some1 or c=:some2" is true if and only if "c=:some2" is true.

Regards
Michel
Re: Sql qyery [message #262558 is a reply to message #262531] Mon, 27 August 2007 08:48 Go to previous messageGo to next message
pablolee
Messages: 2836
Registered: May 2007
Location: Scotland
Senior Member
I mis-read/ misunderstood the question. Thanks Michel
Re: Sql qyery [message #262560 is a reply to message #262558] Mon, 27 August 2007 09:04 Go to previous messageGo to next message
Michel Cadot
Messages: 64152
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Actually I read it the same as you, this is only when I tried to find a tricky alternate way for decode (coalesce, lnnvl) that I realized this is not the proper way to see the issue.

Regards
Michel
Re: Sql qyery [message #262579 is a reply to message #262522] Mon, 27 August 2007 11:06 Go to previous message
dimis283
Messages: 38
Registered: July 2007
Location: greece
Member
Thank you.
I make a test and I thing it is so simple.
I wanted to make a different version of a query (using the "in" statement) for a lov (Forms) and I confused-maybe I tested a wrong query.
Dimis
Previous Topic: PL/SQL Tables
Next Topic: Add Months
Goto Forum:
  


Current Time: Sat Dec 10 08:51:17 CST 2016

Total time taken to generate the page: 0.21098 seconds