Re: DECODE or else, a little test...

From: Ron Jorissen <para3_at_xs4all.nl>
Date: 1996/11/13
Message-ID: <328977AE.3ADB_at_xs4all.nl>#1/1


L. Tseng wrote:
>
> DECODE() is probably the most powerful function in Oracle.
>
> For example
>
>
> IF colA = 1 AND colB = 1 THEN 'YES'
> ELSE 'NO'
>
> can be converted as
>
> DECODE(colA, 1, DECODE(colB, 1, 'YES', 'NO'), 'NO')
>
> BUT.....
>
> Can DECODE do the following?
>
> IF colA > 100 THEN 'A'
> ELSIF colA = 100 THEN 'B'
> ELSE 'C'
>
> Thanks,
>
> Leslie
>
Yes if you mix decode with the sign function. Try this decode(sign(colA-100),1,'A',0,'B','C') The function sign does the following: if colA < 100 (colA-100

becomes                                       negative) it returns -1
                                      if colA > 100 (colA-100
becomes                                       positive) it returns 1
                                      if colA = 100 (colA-100 becomes
0) 									                                      it returns 0
Received on Wed Nov 13 1996 - 00:00:00 CET

Original text of this message