MySQL 中是否有与 Oracle 的 NVL 等效的功能?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7239498/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:57:45  来源:igfitidea点击:

Is there a function equivalent to the Oracle's NVL in MySQL?

mysqlcoalescenvl

提问by Thilo

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.

我正在从表格中选择一列的最大值。但是有一个问题:如果表中没有行,则返回 null。

I want to use a function which will return a certain value if the result is null. For example with Oracle there is the NVLfunction which gives a certain value if the column is null. Is there an equivalent function in MySQL ?

我想使用一个函数,如果结果为空,它将返回某个值。例如,对于 Oracle,NVL如果列为空,则有一个函数会给出某个值。MySQL 中是否有等效的功能?

回答by Thilo

Use coalesce:

使用合并

select coalesce(column_name, 'NULL VALUE') from the_table