Compact conditional expressions that return one of two or more values based on a condition, without the full verbosity of CASE WHEN. Includes IIF (SQL Server, Access), DECODE (Oracle), and IF (MySQL).
Conditional logic in SQL: IF(condition, true_val, false_val) in MySQL, DECODE(expr, val1, result1, ...) in Oracle. CASE is more portable across databases and supports multiple conditions. NVL2 and IIF provide shorthand for common patterns.
| Database System | Support Status | Since Version | Notes |
|---|---|---|---|
| MySQL | ✓ Supported | 3.23 | IF(condition, true_val, false_val) is the primary ternary conditional. IFNULL(expr, fallback) is shorthand for the NULL-check case. IIF is not supported. DECODE is not supported. All three are non-standard; the portable equivalent is CASE WHEN ... END. |
| PostgreSQL | ✗ Not Supported | — | PostgreSQL does not support IIF, DECODE, or IF as conditional functions. The standard CASE WHEN ... END expression covers all use cases. COALESCE and NULLIF handle the common NULL-check patterns. No shorthand alternative — use CASE. |
| SQL Server | ✓ Supported | 2012 | IIF(condition, true_val, false_val) added in SQL Server 2012 (ported from Microsoft Access). It is syntactic sugar for CASE WHEN condition THEN true_val ELSE false_val END — the query optimizer treats them identically. CHOOSE(index, val1, val2, ...) also added in 2012, returns the value at the 1-based index position. DECODE is not supported. |
| Oracle | ✓ Supported | 7 | DECODE(expr, search1, result1, search2, result2, ..., default) is Oracle's proprietary multi-branch conditional, available since Oracle 7. It handles NULLs specially — DECODE treats two NULLs as equal (unlike = comparison). IIF is not supported. Oracle 9i+ supports the standard CASE WHEN expression alongside DECODE. NVL(expr, default) is the Oracle shorthand for NULL checking (equivalent to COALESCE with two args). |
| SQLite | ✗ Not Supported | — | SQLite does not support IIF, DECODE, or IF as functions. CASE WHEN ... END is the only conditional expression. COALESCE and IFNULL (SQLite does support IFNULL as an alias for COALESCE with two arguments) handle NULL checks. |
The fully portable form is always CASE WHEN ... THEN ... ELSE ... END — supported by every engine since early versions. IIF exists in SQL Server (2012+) and SQLite (3.32.0+) but nowhere else. Oracle's DECODE is unique: it treats NULL = NULL as true (unlike every other comparison in SQL), making it subtly different from CASE WHEN col IS NULL. MySQL's IF() function is only available in MySQL — do not use it in cross-engine schemas. For NULL-check shorthand: COALESCE is the most portable (SQL standard), NVL is Oracle-only, IFNULL works in MySQL and SQLite, ISNULL works in SQL Server.
IF(condition, true_val, false_val) is the primary ternary conditional. IFNULL(expr, fallback) is shorthand for the NULL-check case. IIF is not supported. DECODE is not supported. All three are non-standard; the portable equivalent is CASE WHEN ... END.
PostgreSQL does not support IIF, DECODE, or IF as conditional functions. The standard CASE WHEN ... END expression covers all use cases. COALESCE and NULLIF handle the common NULL-check patterns. No shorthand alternative — use CASE.
IIF(condition, true_val, false_val) added in SQL Server 2012 (ported from Microsoft Access). It is syntactic sugar for CASE WHEN condition THEN true_val ELSE false_val END — the query optimizer treats them identically. CHOOSE(index, val1, val2, ...) also added in 2012, returns the value at the 1-based index position. DECODE is not supported.
DECODE(expr, search1, result1, search2, result2, ..., default) is Oracle's proprietary multi-branch conditional, available since Oracle 7. It handles NULLs specially — DECODE treats two NULLs as equal (unlike = comparison). IIF is not supported. Oracle 9i+ supports the standard CASE WHEN expression alongside DECODE. NVL(expr, default) is the Oracle shorthand for NULL checking (equivalent to COALESCE with two args).
SQLite does not support IIF, DECODE, or IF as functions. CASE WHEN ... END is the only conditional expression. COALESCE and IFNULL (SQLite does support IFNULL as an alias for COALESCE with two arguments) handle NULL checks.