Solved

oracle where clause

Posted on 2010-11-23
3
503 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 32

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that useā€¦
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

860 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