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

if(..) statement in Oracle?

From: Peter Bryant <pbryant_at_bigfoot.NOSPAM.com>
Date: Sun, 9 Jan 2000 11:16:37 +1300
Message-ID: <947369413.108846@shelley.paradise.net.nz>


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 - 16:16:37 CST

Original text of this message

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