DECODE IN ORACLE

and area_rep_no = decode(:p_rep_id,'ALL','',:p_rep_id)

If parameter p_rep_id is ALL then I want all the reps else only the once chosen by the parameter.

Thanks in advance.  My above decode is giving me only if I choose rep id. If I choose 'ALL' nothing is being displayed.
LVL 6
anumosesAsked:
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.

mankowitzCommented:
how about

WHERE (:p_rep_id='ALL' OR area_rep_no=:p_rep_id)
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
anumosesAuthor Commented:
This is my actual query

select (sum(actual_draw)/goals) * 100 as percent_to_goal
from proposed_goal a, blood_drives b
where a.rep_id = b.area_rep_no
  and a.month = substr(:P_MON_YEAR,1,3)  
  and year = substr(:P_MON_YEAR,5,4)
  and area_rep_no = decode(:p_rep_id,'ALL','',:p_rep_id)
  and drive_date between to_date(:P_MON_YEAR,'Mon YYYY')
              and last_day(to_date(:P_MON_YEAR,'Mon YYYY'))       
  group by goals;      

If ALL then I want the sum for all reps
0
Swadhin RaySenior Technical Engineer Commented:
Try this:
create table 
  xx_dil_tab ( col1 number , col2 varchar2(100));
  
  
  begin
  insert into xx_dil_tab values(1, 'open');
  insert into xx_dil_tab values(2, 'open');
  insert into xx_dil_tab values(3, 'close');
  insert into xx_dil_tab values(4, 'close');
  insert into xx_dil_tab values(5, 'open');
  insert into xx_dil_tab values(6, 'open');
  commit;
  end;
      
 
 
CREATE OR REPLACE FUNCTION search(ip_input VARCHAR2) RETURN VARCHAR2 IS
        l_output VARCHAR2(4000);
        l_input  VARCHAR2(4000);
BEGIN
        l_input := ip_input;
        IF l_input IS NULL
        THEN
                l_output := NULL;
        ELSIF l_input = 'ALL'
        THEN
                l_output := NULL;
        ELSE
                l_output := ip_input;
        END IF;
        RETURN l_output;
END;
 
 
SELECT *
  FROM xx_dil_tab
WHERE nvl(col2
          ,'NULL') = nvl(search(:gs_name)
                        ,nvl(col2
                            ,'NULL'));

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

slightwv (䄆 Netminder) Commented:
Take the 'OR' example above and use it.  No need for a special function

Change from:
...
 and area_rep_no = decode(:p_rep_id,'ALL','',:p_rep_id)
...

To:
...
and  (:p_rep_id='ALL' OR area_rep_no=:p_rep_id)
...
0
slightwv (䄆 Netminder) Commented:
It's the same logic as your previous question:
http://www.experts-exchange.com/Database/Oracle/Q_27238427.html
0
anumosesAuthor Commented:
THANKS
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.