mysqlÖÐCOALESCEº¯ÊýΪʲô»áʧЧ
mysql ÖÐ coalesce º¯ÊýʧЧµÄÔµ¹ÊÔÓÉÊÇ£º²ÎÊýÈ«ÊÇ null²ÎÊýÀàÐͲ»¼æÈÝת´ï null ±í´ïʽ´ÎÒª¹ýʧ
MySQL ÖÐ COALESCE º¯ÊýʧЧµÄÔµ¹ÊÔÓÉ
COALESCE º¯ÊýÊÇÒ»¸öÓÐÓõĺ¯Êý£¬Ëü·µ»Øת´ï¸øËüµÄµÚÒ»¸ö·Ç NULL ²ÎÊý¡£È»¶ø£¬ÔÚijЩÇéÐÎÏ£¬COALESCE º¯Êý¿ÉÄÜ»áʧЧ¡£
ʧЧԵ¹ÊÔÓÉ£º
²ÎÊýÈ«ÊÇ NULL£ºÈôÊÇת´ï¸ø COALESCE µÄËùÓвÎÊý¶¼ÊÇ NULL£¬Ôò¸Ãº¯Êý½«·µ»Ø NULL¡£
²ÎÊýÀàÐͲ»¼æÈÝ£ºÈôÊÇת´ïµÄ²ÎÊýÀàÐͲ»¼æÈÝ£¬Ôò COALESCE º¯Êý½«·µ»Ø NULL¡£ÀýÈ磬ÈôÊÇʵÑ齫×Ö·û´®ÓëÊý×ÖÍŽáʹÓã¬Ôòº¯Êý»áʧЧ¡£
NULL ±í´ïʽ£ºÈôÊÇת´ïµÄij¸ö²ÎÊýÊÇ NULL ±í´ïʽ£¬¶ø²»ÊÇ NULL Öµ£¬Ôò COALESCE º¯ÊýÒ²»áʧЧ¡£
´ÎÒª¹ýʧ£ºÈôÊÇÅÌÎÊÖб¬·¢ÁË´ÎÒª¹ýʧ£¬ÀýÈçÓï·¨¹ýʧ£¬Ôò COALESCE º¯Êý¿ÉÄÜ»áʧЧ¡£
ÆäËû×¢ÖØÊÂÏ
COALESCE º¯ÊýÊǶèÐԵģ¬ÕâÒâζ×ÅËüÖ»ÔÚÐèҪʱ²ÅÅÌËãЧ¹û¡£Õâ¿ÉÄܻᵼÖÂһЩÒâÍâµÄЧ¹û£¬ÀýÈ磺
SELECT COALESCE(NULL, 5) + 1;
µÇ¼ºó¸´ÖÆ
Õ⽫·µ»Ø 7£¬¶ø²»ÊÇ NULL£¬ÓÉÓÚ COALESCE ²»»áÅÌËã NULL ±í´ïʽ¡£
COALESCE º¯ÊýÔÚijЩÇéÐÎÏ¿ÉÄÜ±È ISNULL() »ò IFNULL() º¯Êý¸üÓÐÓá£
½â¾öÒªÁ죺
ΪÁË×èÖ¹ COALESCE º¯ÊýʧЧ£¬¿ÉÒÔ½ÓÄÉÒÔϲ½·¥£º
È·±£×ª´ïµÄ²ÎÊý²»ÊÇ NULL¡£
È·±£²ÎÊýÀàÐͼæÈÝ¡£
ʹÓà ISNULL() »ò IFNULL() º¯ÊýÀ´Ìæ»» COALESCE£¬ÒÔ´¦Àí NULL ±í´ïʽ¡£
ɨ³ýÅÌÎÊÖеÄÈκδÎÒª¹ýʧ¡£
ÒÔÉϾÍÊÇmysqlÖÐCOALESCEº¯ÊýΪʲô»áʧЧµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡