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: if(..) statement in Oracle?

Re: if(..) statement in Oracle?

From: Gene Hubert <ghubert_at_skillspoint.com>
Date: Sun, 09 Jan 2000 00:18:25 GMT
Message-ID: <3877d312.472404041@news.interpath.net>


You can get much of what you want by using the sign() function inside of decode(). Sign() returns -1, 0 or 1 depending on the result of evaluating a numeric expression.

Gene Hubert
SkillsPoint.com
ghubert_at_skillspoint.com
919-462-3229 (w)
503-884-5353 (f)

http://www.skillspoint.com - Where smart people go to buy the right training!

On Sun, 9 Jan 2000 11:16:37 +1300, "Peter Bryant" <pbryant_at_bigfoot.NOSPAM.com> wrote:

>I am converting an application from MySQL to Oracle. MySQL has an if(...)
>statement. I was wondering if there was anything similar for Oracle. Is
>decode the closest? If so then is there anyway to use contitionals in the
>statement - e.g. decode(1>2, true, '1 > 2', false, 'err')
>
>The MySQL syntax is:
>
>IF(expr1,expr2,expr3)
>If expr1 is TRUE (expr1 <> 0 and expr1 <> NULL) then IF() returns expr2,
>else it returns expr3. IF() returns a numeric or string value, depending on
>the context in which it is used.
>mysql> select IF(1>2,2,3);
> -> 3
>mysql> select IF(1<2,'yes','no');
> -> 'yes'
>mysql> select IF(strcmp('test','test1'),'yes','no');
> -> 'no'
>
>expr1 is evaluated as an integer value, which means that if you are testing
>floating-point or string values, you should do so using a comparison
>operation.
>mysql> select IF(0.1,1,0);
> -> 0
>mysql> select IF(0.1<>0,1,0);
> -> 1
>
>In the first case above, IF(0.1) returns 0 because 0.1 is converted to an
>integer value, resulting in a test of IF(0). This may not be what you
>expect. In the second case, the comparison tests the original floating-point
>value to see whether it is non-zero. The result of the comparison is used as
>an integer.
>
>
Received on Sat Jan 08 2000 - 18:18:25 CST

Original text of this message

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