Re: if-then-else expression in SELECT list

From: Jonathan W. Ingram <jonathan.ingram_at_attws.com>
Date: 1996/08/01
Message-ID: <3200E639.3462_at_attws.com>#1/1


ashok kapur wrote:
>
> You can perform equality conditions using DECODE.
>
> DECODE works as follows:
> DECODE(<column_name>, [<value>,<result>], <default>)
> where <colunmn_name> is the name of the column
> <value> is one of the values the column can have
> <result> is the column name has that <value> then the decode
> stmt. will return <result>
> <default> is returned when the column_name's values does not
> match any of te given <vale>s.

I've seen several responses that say exactly the same thing, but none of them have mentioned that several conditions can be tested for with a single decode statement! For instance:

   decode (dept, '001', 'ACCOUNTING', '002', 'MARKETING', '003', 'SALES',

                 '004', 'MANUFACTURING', 'SUPPORT');

This statement tests for 4 conditions and returns the appropriate value. If none of the 4 conditions is true, 'SUPPORT' is returned.

Jonathan Received on Thu Aug 01 1996 - 00:00:00 CEST

Original text of this message