[MySQL function] Use of MYSQLIFNULL and IF functions _ MySQL

Source: Internet
Author: User
[MySQL function] MYSQLIFNULL and IF functions use bitsCN.com

[MySQL function] Use of mysql ifnull and IF functions

The usage of the mysql ifnull function is described in detail below for your reference. if you have encountered similar problems in using the mysql ifnull function, take a look.

MYSQL IFNULL(expr1,expr2)     

If expr1 is not null, IFNULL () returns expr1; otherwise, it returns expr2. IFNULL () returns a number or string value, depending on the context in which it is used.

mysql> select IFNULL(1,0);                           -> 1      mysql> select IFNULL(0,10);                           -> 0      mysql> select IFNULL(1/0,10);                           -> 10      mysql> select IFNULL(1/0,'yes');                           -> 'yes '    

IF (expr1, expr2, expr3)

IF expr1 is TRUE (expr1 <> 0 and expr1 <> NULL), IF () returns expr2; otherwise, expr3 is returned. IF () returns a number or string value, depending on the context in which it is used.

mysql> select IF(1>2,2,3);                           -> 3      mysql> select IF(1<2,'yes','no');                           -> yes     mysql> select IF(strcmp('test','test1'),'yes','no');   //strcmp('test','test1')=-1                        -> yes     

BitsCN.com

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.