SQLserver中ISNULL函數與Mysql中IFNULL函數的用法,isnullifnull

來源:互聯網
上載者:User

SQLserver中ISNULL函數與Mysql中IFNULL函數的用法,isnullifnull

本文介紹下,sql server中的isnull函數,以及mysql中的ifnull函數,介紹二者的具體用法與區別,有興趣的朋友可以研究下哦。

先來看SQL Serve的ISNULL函數:

ISNULL(check_expression,replacement_value)

1、check_expression與replacement_value的資料類型必須一致。
2、如果check_expression為NULL,則返回replacement_value。
3、如果check_expression為NULL,則返回check_expression。

再來看Mysql的IFNULL函數:

IFNULL(expr1,expr2)
如果expr1不是NULL,IFNULL()返回expr1,否則返回expr2。

下面來看下SQLServer中ISNULL與NULLIF的具體用法。
SQL Server裡的 ISNULL 與 ASP 中的 IsNull不同,SQL Server 中有兩個參數。

一,ISNULL 文法:
ISNULL(check_expression, replacement_value)

1,check_expression 與 replacement_value 資料類型必須一致
2,如果 check_expression 為 NULL,則返回 replacement_value
3,如果 check_expression 不為 NULL,則返回 check_expression

二,NULLIF 用於檢查兩個運算式。
文法:
NULLIF(expression, expression)

說明:
如果兩個 expression 相等,則返回 NULL,該 NULL 為第一個 expression 的資料類型。
如果兩個 expression 不相等,則返回第一個 expressio。


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.