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

Thread: decode function

  1. #1
    Join Date
    Nov 2000
    Posts
    65

    Exclamation

    Hi

    I have used decode function to implement ifelseendif logic.
    decode(field, matched value1, returned value1, matched for value2, returned value2, default if nothing else matches)

    What if I need to implement the following logic
    (field, > matched value1, returned value1, >matched for value2, returned value2, default if nothing else matches)

    Any ideas.

    Thank you,
    nk

  2. #2
    Join Date
    May 2000
    Location
    ATLANTA, GA, USA
    Posts
    3,135
    Yes, you can do it.

    Within a decode function , you can have another decode function.

  3. #3
    Join Date
    Nov 2000
    Posts
    65
    I guess, I need help with this one

    Let’s say we have an EMP table as below

    ****************
    Name* points
    ab * 3200
    dc * 100
    ef * 20
    gh * 0
    *****************

    and you need to generate a report with columns name and commission ( where commission is decided based on the following conversion table)

    ******************
    point_range * commission
    0-100 * 0
    101-500 * 50
    501-1500* 1000
    1501-3000 * 2000
    3000+ * 2500
    *******************

    How would one implement the above requirement, using decode function.

    Thank you,
    nk


  4. #4
    Join Date
    Aug 2000
    Location
    Ny
    Posts
    105
    Use "CASE" it's faster and easyer to use, see Oracle doc.

  5. #5
    Join Date
    Jul 2000
    Posts
    521
    nk,

    If your requirement is as simple as the one you stated, us SIGN function to decide the which range the POINTS fall in and DECODE output of SIGN.

    If you need, I can post the SQL statement.
    svk

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