Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2001
    Location
    Lexington, KY
    Posts
    606

    Unanswered: CASE in Oracle 8 (not 8i)...

    Oracle 8 does not have the CASE command.

    I have a table with one of three values: L, M, H in a column. I would like to sort H M L, but I can't do this because dictionary sort is different -- so I was thinking of doing a CASE so that H=2, M=1, L=0 (or somesuch). I could always change it so that I actually have a 2, 1, 0 in there but I would rather make the SQL statement do this.

    Thanks.
    Thanks,

    Matt

  2. #2
    Join Date
    Nov 2002
    Location
    Desk, slightly south of keyboard
    Posts
    697
    Hi Matt,

    Check out the decode function. Probably something like...


    select LMHColumn
    from yourtable
    order by decode( LMHColumn,'H',1,'M',2,'L',3,4)

    (The last parameter '4' would equate to the "otherwise/else" part of the case condition).

    Bear in mind such an order by cannot be optimised.

    HTH
    Bill

  3. #3
    Join Date
    Mar 2001
    Location
    Lexington, KY
    Posts
    606
    Excellent. I knew MySQL had a similar function but I could not remember the name -- I tried searching for 'encode' but as you might expect I didn't find what I was looking for.
    Thanks,

    Matt

Posting Permissions

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