Ifnull, ISNULL, Nullif usage in MYSQL (database empty)

Source: Internet
Author: User

Source: http://blog.csdn.net/a466350665/article/details/52994761

http://blog.csdn.net/xingyu0806/article/details/52080962

ifnull (EXPR1,EXPR2) usage: if EXPR1 is not NULL, the return value of Ifnull () is expr1; Otherwise its return value is EXPR2. The return value of Ifnull () is either a number or a string, depending on the context in which it is used.

      mysql>   SELECT   ifnull (1,0);   
    & nbsp                         1   
      mysql>   SELECT   ifnull (null,10);  &NBSP
                            &N Bsp  &NBSP
      mysql>   SELECT   ifnull (1/0,10);   
    &nbs P                           
      mysql>   SELECT   ifnull (1/0, ' yes ');  &NBSP
                            &N Bsp ' Yes '   the default result value for
      ifnull (EXPR1,EXPR2) is one of the more "common" in two expressions, in the order of string, real, or INTEGER.

ISNULL (expr) usage: If expr is null, then the return value of ISNULL () is 1, otherwise the return value is 0.

mysql> Select IsNull (+);
0
Mysql> Select IsNull (1/0);
1
The comparison of NULL values using = is usually wrong.

nullif (EXPR1,EXPR2) Usage: If EXPR1 = EXPR2 is established, then the return value is NULL, otherwise the return value is EXPR1. This is the same as when the case is Expr1 = Expr2 then NULL ELSE expr1 end.

Mysql> SELECT Nullif ();
, NULL
Mysql> SELECT Nullif;
1
If the arguments are not equal, the MySQL two-time value is expr1.

Ifnull, ISNULL, Nullif usage in MYSQL (database empty)

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.