Re: if else logic in SQLPlus scripts

From: Odd Morten Sveås <odd.morten.sveas_at_accenture.com>
Date: 21 Sep 2002 12:32:02 -0700
Message-ID: <4306a83.0209211132.5027b5e3_at_posting.google.com>


> Do you mean the DECODE command? It functions as a kind of simple
> if/then/else operator
>
> DECODE(value, if1,then1[,if2,then2,]...., else)
>

The DECODE, and often used together with the sign() function, should acomplish most of the if then else functionality.

The problem with SECODE is that you only can determin wheter the value is equal to somthing. Not grather or less than. But if you use the sign() function that return 1 or -1 depending on the sign of the argument you can determin if an value is grater or less then zero. And by using an offset you can check against witch value you want.

EG:

SELECT
[Quoted]  DECODE( sign( a - 15 ),

         -1 , 'Less than 15',
         'Grater or equal to zero' )

FROM DUAL; Received on Sat Sep 21 2002 - 21:32:02 CEST

Original text of this message