Here’s the MySQL equivalent of Oracle’s NVL and MSSQL/Sybase’s ISNULL functions.
Syntax
IFNULL(expr1,expr2)
Usage
If expr1 is not NULL, IFNULL() returns expr1; otherwise it returns expr2. Take note that IFNULL() returns a numeric or string value, depending on the context in which it is used. I haven’t used it for other data types yet but I reckon it would have the same results. That is to return the same data type as that of expr1. Another important thing to remember is that expr1 and expr2 should have the same data type
Incoming search terms:
- nvl mysql
- mysql nvl equivalent
- nvl in mysql
- mysql nvl
- oracle nvl mysql
- nvl equivalent in mysql
- mysql nvl equivalent function
- mysql аналог nvl
- oracle nvl
- NVL Oracle
Related posts:
If you want empty string to be null as well you could use:
eg.
update mytable set
name = ifnull(nullif(‘newval’,”), name)
where id=1
ps. also, when newval are only spaces, nullif also gives null as a result
thanks! I’ll take note of that.