Solved

decode statement in oracle

Posted on 2013-05-30
2
425 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 74

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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

617 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