IF

2025-11-19 10:08:12  Updated

Syntax

IF(expr1,expr2,expr3)

Purpose

If the value of expr1 is TRUE, which means that expr1 <> 0 and expr1 <> NULL, the returned result is expr2. Otherwise, the returned result is expr3.

The returned result of IF() can be a numeric or string value. This depends on the arguments of the function.

If only one of expr2 and expr3 is NULL, the result of IF() is an non-NULL expression.

Examples

obclient> SELECT IF(5>6, 'T','F'), IF (5>6, 1, 0), IF(NULL, 'TRUE', 'FALSE'), IF(0, 'TRUE', 'FALSE')\G
*************************** 1. row ***************************
         IF(5>6, 'T','F'): F
           IF (5>6, 1, 0): 0
IF(NULL, 'TRUE', 'FALSE'): FALSE
   IF(0, 'TRUE', 'FALSE'): FALSE
1 row in set

Contact Us