Oracle NVL equivalent in MySQL

Read – What is Oracle NVL

Many Oracle Developers who write code in MySQL will look for this solution.

Answer 1 :- IFNULL

Answer 2 :- COALESCE ( It returns first not null expression in the list)

IFNULL

mysql> select IFNULL(null,1);
will return 1

COALESCE

mysql> select COALESCE(null,1);
will return 1

Note:- COALESCE will work in Oracle too.

2 responses to “Oracle NVL equivalent in MySQL”

  1. Oracle NVL Function replace NULL values with a given value in the result of a query. Oracle NVL Function takes two parameters. If expression of first parameter is not null then NVL returns the expression of first parameter, otherwise returns the expression of second parameter. See details:
    http://www.rahinur.com/oracle-functions/oracle-nvl-function.html

  2. great insight. Really enjoyed reading this blog. Keep up the good work and to everyone keep on learning!