DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: Which is faster: Decode or If/Else

Hybrid View

  1. #1
    Join Date
    Oct 2001
    Posts
    22
    I have a select statement that returns one value that goes something like this:

    select decode(sign(nvl(sum(a), 0), nvl(sum(b)/sum(c)),0), 1, decode(sign(nvl(sum(b),0) / nvl(sum(c),0)), -1, 5), 2)
    from table1

    now, the select above is just an example and the one im using is actually longer than that, uses 3 more decodes in that first decode.
    Now, would this be code optimization or should i do one select returning the sum value of a, b, c and then do my calculation in a series of if/else statements?

    Thanx in advance
    Peace
    Sakitah

  2. #2
    Join Date
    Sep 2001
    Location
    NJ, USA
    Posts
    1,287
    If u use oracle 8i and 9i u may use CASE expression.
    DECODE() and CASE .. WHEN .. on server side
    in any case faster then IF/ELSE on client side.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width