Is there a function equivalent to the Oracle's NVL in MySQL?
I'm selecting the max of a column from a table. But there is one problem: if there are no rows in the table, it returns null.
I want to use a function which w开发者_高级运维ill return a certain value if the result is null. For example with Oracle there is the NVL
function which gives a certain value if the column is null. Is there an equivalent function in MySQL ?
Use coalesce:
select coalesce(column_name, 'NULL VALUE') from the_table
or you can use IFNULL(expr1,expr2)
If expr1 is not NULL, IFNULL() returns expr1; otherwise it returns expr2.
select IFNULL(column_name, 'NULL VALUE') from the_table;
taken from: https://dev.mysql.com/doc/refman/8.0/en/flow-control-functions.html#function_ifnull
精彩评论