Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: CASE construct in SELECT statement

Re: CASE construct in SELECT statement

From: Myron Wintonyk <mwintony_at_med.ualberta.ca>
Date: Thu, 18 Jan 2001 16:03:28 +1000
Message-ID: <3A668730.E6C39CEE@med.ualberta.ca>

Perhaps I'm missing something. The statement looks O.K. to me as is. Here is a statement that I tried (and it worked fine) ...

SELECT CASE WHEN rownum>80 THEN 'big time'

                          WHEN rownum < 20 THEN 'small fry'
                           ELSE 'middle management' END
              FROM user_segments;


Anson Parker wrote:

> Ok, I'm pretty green with Oracle - I'm a MySQL user most of the
> time. I'm currently trying to provide Oracle support in a web application
> I've built currently for MySQL. So far I've been able to survive on the
> Oracle Technet docs - that is until now...
>
> (BTW: I'm running Oracle 8.1.6 on Linux)
>
> In MySQL I have a rather large select statement making use of a case
> construct. It looks something like this (to use the infamous employee e.g.):
>
> SELECT firstname, lastname, CASE WHEN salary>80000 THEN 'big time'
> WHEN salary < 20000 THEN 'small fry' ELSE 'middle management' END
> FROM employee_table;
>
> You should be able to see the basic principle anyway. I'd like to do this
> same
> logic in a PL/SQL statement to my Oracle database (obviously the above
> example is a custom MySQL extension).
>
> Can I do this inline (within a SELECT statement)? Or do I have to venture
> into
> the deep unknown of procedures? It's not a common query and it's the only
> time I have to stray beyond basic SQL calls so I'd rather stick to the
> inline
> method, albeit a little offensive to the eye, if I can.
>
> Anson.
Received on Thu Jan 18 2001 - 00:03:28 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US