Solved

decode statement in oracle

Posted on 2013-05-30
2
417 Views
Last Modified: 2013-05-30
select ri.customer_id,c.name,c.ar_account,inv_product_type,
       ri.unit_id,substr(ri.product_code,1,5) product_code,
       mc.description,
         ri.return_reason_code,
         ri.exp_date,trunc(return_date) return_date
  from return_advices@plab.world ra,
       return_items@plab.world ri,
         valid_products@plab.world vp,
         customers@plab.world c,
         units@plab.world u,
         master_codes mc
 where ri.return_advice_id = ra.return_advice_id
   and vp.product_code = substr(ri.product_code,1,5)
   and c.customer_id = ri.customer_id
   and u.unit_id = ri.unit_id
   and u.system_label_decision = substr(mc.udf1, 1,2)
   and mc.term_date is null
   and ri.move_date between '01-may-2013' and '02-may-2013'  
and decode(:p_inv_type
 order by c.ar_account,return_date

-------------------------I need help in the decode statement

If :p_inv_type = 'LPHER' then get vp.inv_product_type = 'LPHER'
elsif p_inv_type  = 'RBC LRBC'   then

I want vp.inv_product_type in ('RBC','LRBC')

I know I have asked these many times, but this is a little different.
0
Comment
Question by:anumoses
2 Comments
 
LVL 73

Accepted Solution

by:
sdstuber earned 250 total points
Comment Utility
don't use decode (or case)  put the conditions directly into the where clause

and (
    (p_inv_type = 'LPHER' and vp.inv_product_type = 'LPHER')
   or
    (p_inv_type  = 'RBC LRBC'  and vp.inv_product_type in ('RBC','LRBC'))
)


using decode on the column prevents the optimizer from considering all options,
most notably indexes  but it also skews the costing algorithms
0
 
LVL 6

Author Closing Comment

by:anumoses
Comment Utility
thanks
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
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…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now