How does the isnull function in MSSQL be implemented in MySQL...

Source: Internet
Author: User

How to Implement the isnull function in mssql in mysql

========================================================== ============

IFNULL (expr1, expr2)
If expr1 is not NULL, the returned value of IFNULL () is expr1;
Otherwise, the returned value is expr2. The returned value of IFNULL () is a number or string, depending on the context in which it is used.

Code

Mysql> select ifnull (1, 0 );

-> 1


Mysql> select ifnull (NULL, 10 );


-> 10

Mysql> select ifnull (1/0, 10 );

-> 10

Mysql> select ifnull (1/0, 'yes ');

-> 'Yes'

 


The default result value of ifnull (expr1, expr2) is one of the two expressions that is more "common", in the order of string, real, or
Integer. Assume that an expression-based table or MySQL must store the returned value of ifnull () in a temporary table in internal memory:

 

Create table tmp select ifnull (1, 'test') AS test;

 


In this example, the test column type is Char (4 ).

NULLIF (expr1, expr2)
If expr1 = expr2 is true, the return value is NULL. Otherwise, the return value is expr1. This is the same as case when expr1 = expr2 then null else expr1 END.

Mysql> select nullif (1, 1 );

-> NULL

Mysql> select nullif (1, 2 );

-> 1

 

Note: If the parameters are not equal, the value obtained by MySQL twice is expr1.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.