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

Home -> Community -> Usenet -> c.d.o.server -> Re: Conditional Select statement

Re: Conditional Select statement

From: <xmark.powell_at_eds.com.x>
Date: 5 Apr 2001 13:00:20 GMT
Message-ID: <9ahq94$vla$1@news.netmar.com>

In article <5aHy6.18908$XV.4868342_at_news3.rdc1.on.home.com>, The Ghost <The_at_Ghost.com> writes:
>select decode(field,'OK','this is the correct value','this is not the
>correct_value')
>from your_table
>
>
>"Jon" <jzuazoa_at_nexo.es> wrote in message
>news:9afe0b$bn1$1_at_unbe.sarenet.es...
>> Hi,
>>
>> I would like to know if it is posible to add some conditional behaivour to
 a
>> select statement. I mean that if have a table that contains sometimes the
>> 'OK' value and 'FAIL' for other rows so I could create a statement that
 when
>> the row contains 'OK' it would print 'this is the correct value' and on
 the
>> other hand when it contains 'FAIL' it just prints 'this is not the correct
>> value'
>>
>>
>> Thanks for you help
>>
>> PS. this task is accomplish in SYBASE using 'CASE WHEN...'
>>
>>

The previous post told you how to use decode which is fine for versions 8 and lower, but if have 8.1 you can use the SQL CASE statement like this:

UT1> SELECT CASE WHEN rownum > 07 THEN 'big time'

  2              WHEN rownum < 04 THEN 'small fry'
  3              ELSE 'middle management' END as "CASE WHEN"
  4 FROM all_tables
  5 WHERE rownum < 10 ;

CASE WHEN



small fry
small fry
small fry
middle management
middle management
middle management
middle management
big time
big time

9 rows selected.

Received on Thu Apr 05 2001 - 08:00:20 CDT

Original text of this message

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