We help IT Professionals succeed at work.

DECODE IN ORACLE

anumoses
anumoses asked
on
233 Views
Last Modified: 2014-08-21
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.
Comment
Watch Question

CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

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
CERTIFIED EXPERT

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

CERTIFIED EXPERT
Most Valuable Expert 2012
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Most Valuable Expert 2012
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
THANKS
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.