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!

multiple conditional parameters in where clause

695799Jul 15 2009 — edited Jul 15 2009
How can I select records from a table , say emp, when I have a parameter for where condition like
if empno is known then use in where clause,
if ename is known then use ename in where clause,
if both are known then use both parameters in where clause.

I am using Oracle 9i.
psuedo code.
...
if p_empno is not null and p_ename is not null then
select * from emp 
where empno=p_emp and ename = p_ename ;
elsif p_empno is null and p_ename is not null then
select * from emp 
where ename = p_ename ;
elsif p_empno is not null p_ename is null then
select * from emp 
where empno=p_emp ;
else 
select * from emp 
end if ;
...
how can I do this in sql or plsql


thanks

Edited by: user10999538 on Jul 15, 2009 3:29 AM
This post has been answered by SanjayRs on Jul 15 2009
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 12 2009
Added on Jul 15 2009
11 comments
2,890 views