[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

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.
0
anumoses
Asked:
anumoses
3 Solutions
 
mankowitzCommented:
how about

WHERE (:p_rep_id='ALL' OR area_rep_no=:p_rep_id)
0
 
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now