Solved

decode statement in oracle

Posted on 2013-05-30
2
419 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

911 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

22 Experts available now in Live!

Get 1:1 Help Now