Solved

oracle where clause

Posted on 2010-11-23
3
500 Views
Last Modified: 2012-05-10
experts---
I have to code a where clause in oracle which has the following cases

1. If the input variable is null ignore this column in the where clause
2. if the input variable has value then include this column in the where clause.

ex: select a,b,c
      from table_a
where col_a = input1
and col_b = (if input2 has a value then do the and col_b = input2
else dont )

0
Comment
Question by:chickanna
3 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 125 total points
ID: 34199414
select a,b,c
from table_a
where col_a = input1
and (input2 is null OR col_b = input2)
0
 
LVL 34

Expert Comment

by:johnsone
ID: 34199593

Alternately....
select a,b,c
  from table_a
 where col_a = input1
   and col_b = nvl(input2, col_b)

Open in new window

0
 
LVL 31

Assisted Solution

by:awking00
awking00 earned 125 total points
ID: 34200605
You can also use coalesce
select a,b,c
  from table_a
 where col_a = input1
   and col_b = coalesce(input2, col_b)
 
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now