Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use ISNULL function in SQL

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to use the ISNULL function in SQL, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand it.

The isnull () function in SQL Server:

Isnull (value1,value2)

1. The data types of value1 and value2 must be the same.

2. If the value of value1 is not null, the result returns value1.

3. If value1 is null, the result returns the value of vaule2. Vaule2 is the value you set.

If it is isnull in select, you can determine whether it is null, and if it is given a default value, isnull ("field name", "set default data")

For example: select isnull (score, 0) from xuesheng where name=' Zhang San'in the table xuesheng, if the field score is empty, the result output is 0. If not empty, the value of the field score is output.

Writing with empty fields in sql server, select name from A where name is null/is not null. Not name=null, name=''.

MySQL:

1.isnull (exper) determines whether the exper is empty. If so, it returns 1, otherwise 0.

2.ifnull (exper1,exper2) determines whether exper1 is empty. If so, use exper2 instead.

3.nullif (exper1,exper2) if expr1= expr2 is established, the return value is NULL, otherwise the return value is expr1.

Oracle:

1. Nvl (value1,value2)

What this function means is that if the value of value1 is null, then the function returns the value of value2, and if value1 is not empty, it returns the value of value1.

It is important to note that value1 and value2 keep the field types the same.

2. Nvl2 (value1,value2,value3)

What this function means is that if the value of value1 returns value3 for the null function, otherwise the function returns value2, which means the function will never return value1.

Note that the parameter value2 value3 can be any data type except the LONG type.

3. The format of the NULLIF function is as follows:

NULLIF (expr1,expr2), which means that if the value of the first parameter is equal to the value of the second parameter, null is returned, otherwise the first value is returned.

Thank you for reading this article carefully. I hope the article "how to use the ISNULL function in SQL" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report