博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
coalesce函数_什么是SQL Server COALESCE()函数?
阅读量:2533 次
发布时间:2019-05-11

本文共 3059 字,大约阅读时间需要 10 分钟。

coalesce函数

Hey, folks! In this article, we will be focusing on SQL Server COALESCE() function.

嘿伙计! 在本文中,我们将重点介绍SQL Server COALESCE()函数



了解SQL Server COALESCE()函数 (Understanding SQL Server COALESCE() function)

SQL Server COALESCE() function helps to estimate and return the first NON-NULL value from the set of data or database.

SQL Server COALESCE() function有助于估计并从数据或数据库集中返回第一个NON-NULL值。

In scenarios when we need to fetch or estimate the non-null values from the database, SQL Server COALESCE() function can be used to server the purpose.

在需要从数据库中获取或估计非空值的情况下,可以使用SQL Server COALESCE()函数来达到目的。



SQL Server COALESCE()函数的语法 (Syntax of SQL Server COALESCE() function)

Having understood the working of COALESCE() function, let us get started with the syntax and implementation of the same.

了解了COALESCE()函数的工作原理之后,让我们开始介绍该语法和实现。

Select COALESCE(expressions)

The expressions includes the set of data values to test for the presence of first non-null values.

表达式包括一组数据值,以测试是否存在第一个非空值。

The COALESCE() function returns the first NON-NULL expression from the parameter list.

COALESCE()函数从参数列表返回第一个NON-NULL表达式

If all the expressions in the parameter list are NULL values, then the COALESCE() function returns NULL.

如果参数列表中的所有表达式均为NULL值,则COALESCE()函数将返回NULL。



COALESCE()函数的示例 (Examples of COALESCE() function)

Now let us understand the implementation of COALESCE() function through various examples as mentioned below.

现在,让我们通过下面提到的各种示例来了解COALESCE()函数的实现。

Example 1:

范例1:

SELECT COALESCE(NULL, 'Python', NULL, 'JournalDev.com');

In this example, we passed set of data values that includes two NULL values and two String values. The COALESCE() function returns the first NON-NULL value i.e. ‘Python’.

在此示例中,我们传递了一组包含两个NULL值和两个String值的数据值。 COALESCE()函数返回第一个NON-NULL值,即“ Python”。

Output:

输出:

Python

Example 2:

范例2:

SELECT COALESCE(NULL, NULL, NULL, 100);

In this example, we have passed three NULL values and an integer value. The function returns the integer value as output.

在此示例中,我们传递了三个NULL值和一个整数值。 该函数返回整数值作为输出。

Output:

输出:

100


COALESCE()v / s ISNULL() (COALESCE() v/s ISNULL() )

Many a times, we tend to get confused between two important yet relating functions of SQL Server i.e. COALESCE() function and ISNULL() function.

很多时候,我们倾向于混淆两个重要但又相关SQL Server函数,即COALESCE()函数和ISNULL()函数。

SQL Server COALESCE() function tests for the presence of first NON-NULL value and returns the value.

SQL Server COALESCE() function测试是否有第一个NON-NULL值并返回该值。

On the other side, SQL Server ISNULL() function checks whether the entered expression is NULL or not. If the entered expression is NULL, it returns the value passed to the argument list as output. Else, it returns the expression itself.

另一方面, SQL Server ISNULL() function检查输入的表达式是否为NULL。 如果输入的表达式为NULL,它将返回传递到参数列表的值作为输出。 否则,它返回表达式本身。



结论 (Conclusion)

By this, we have come to the end of this topic. Please feel free to comment below in case you come across any doubts.

至此,我们到了本主题的结尾。 如果您有任何疑问,请随时在下面发表评论。

For more such posts related to SQL Server, please do visit.

有关与SQL Server相关的更多此类帖子,请访问 。



参考资料 (References)

翻译自:

coalesce函数

转载地址:http://poqzd.baihongyu.com/

你可能感兴趣的文章
二维数组中的查找
查看>>
(转)2019JAVA面试题附答案(长期更新)
查看>>
UIButton中setTitleEdgeInsets和setImageEdgeInsets的使用
查看>>
python基础知识笔记(二) (出现语法以及颜色问题)
查看>>
部署docker
查看>>
状态码及其意义
查看>>
【bzoj 十连测】[noip2016十连测第五场]Problem C: travel(模拟)
查看>>
Exp9 WEB安全基础 20154326杨茜
查看>>
关于SQL5005C
查看>>
JQuery EasyUI之DataGrid列名和数据列分别设置不同对齐方式(转)
查看>>
JavaScript中的null与nudefined
查看>>
js节点问题
查看>>
不使用中间变量,交换int型的 a, b两个变量的值。
查看>>
秘书问题
查看>>
nginx日志模块与HTTP过滤模块与sub模块修改返回内容
查看>>
跳转指令
查看>>
Android应用程序设置让程序不出现在近期任务列表中
查看>>
Object Tracking Benchmark
查看>>
python每天进步一点点
查看>>
docker镜像下载
查看>>