NVL2 Function - Oracle to MariaDB Migration

In Oracle, the NVL2(exp, exp2, exp3) function evaluates exp and returns exp2 if exp is not NULL, otherwise, it returns exp3.

MariaDB also provides the NVL2 function (since 10.3.1) in both native and Oracle compatibility modes.

Oracle:

  -- Replace NULL
  SELECT NVL2('John', 'A', 'N/A') FROM dual;
  /* A */
 
  -- Replace NULL
  SELECT NVL2(NULL, 'A', 'N/A') FROM dual;
  /* N/A */

MariaDB - Oracle Compatibility:

  -- Replace NULL
  SELECT NVL2('John', 'A', 'N/A');
  /* A */
 
  -- Replace NULL
  SELECT NVL2(NULL, 'A', 'N/A');
  /* N/A */

For more information, see Oracle to MariaDB Migration - Oracle Compatibility Mode.