Solved

decode statement in oracle

Posted on 2013-05-30
2
420 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
ID: 39208747
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
ID: 39208994
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Via a live example, show how to take different types of Oracle backups using RMAN.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

776 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