Home > Database > Mysql Tutorial > body text

Mysql coalesce()函数认识跟用法

WBOY
Release: 2016-06-07 16:27:05
Original
1177 people have browsed it

Mysql coalesce()函数认识和用法 Mysql coalesce()函数认识和用法 coalesce()解释:返回参数中的第一个非空表达式(从左向右); 鉴于在mysql中没有nvl()函数, 我们用coalesce()来代替。 coalesce相比nvl优点是,coalesce中参数可以有多个,而nvl()中参数就只

Mysql coalesce()函数认识和用法
Mysql coalesce()函数认识和用法

coalesce()解释:返回参数中的第一个非空表达式(从左向右);

鉴于在mysql中没有nvl()函数, 我们用coalesce()来代替。

coalesce相比nvl优点是,coalesce中参数可以有多个,而nvl()中参数就只有两个。

当然,在oracle中也可以使用 case when....then....else......end

(比较强悍,case when 后可以跟表达式)。
  www.2cto.com 
使用示例:a,b,c三个变量。

Sql代码 
select coalesce(a,b,c); 

如果a==null,则选择b;如果b==null,则选择c;如果a!=null,则选择a;如果a b c 都为null ,则返回为null(没意义)。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!