输入banner图图片脚本导航/分类

【MySQL函数】MYSQLIFNULL和IF函数的使用_MySQL

bitsCN.com

【MySQL函数】MYSQL IFNULL和IF函数的使用

下文对MYSQL IFNULL函数的使用进行了详细的叙述,供您参考学习,如果您在MYSQL IFNULL函数使用方面遇到过类似的问题,不妨一看。

MYSQL IFNULL(expr1,expr2)     

如果expr1不是NULL,IFNULL()返回expr1,否则它返回expr2。IFNULL()返回一个数字或字符串值,取决于它被使用的上下文环境。

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)

如果expr1是TRUE(expr1<>0且expr1<>NULL),那么IF()返回expr2,否则它返回expr3。IF()返回一个数字或字符串值,取决于它被使用的上下文。

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