sqlÖÐisnullÊÇʲôÒâ˼
isnull º¯ÊýÓÃÓÚ¼ì²é±í´ïʽÊÇ·ñΪ null£¬ÊÇÔò·µ»ØÖ¸¶¨µÄÌæ»»Öµ£¬²»È»·µ»Ø±í´ïʽ×Ô¼º¡£Ö÷ÒªÓÃ;°üÀ¨£º1. Ìæ»» null ֵΪ·Ç null Öµ£»2. ×èÖ¹Êý¾Ýת»»¹ýʧ£»3. ÏÔʾÓÐÒâÒåµÄÖµ¡£
ISNULL º¯Êý¼°ÆäÓÃ;
ISNULL º¯ÊýÊÇÒ»¸ö SQL º¯Êý£¬ÓÃÓÚ¼ì²é¸ø¶¨±í´ïʽÊÇ·ñΪ NULL¡£ÈôÊDZí´ïʽΪ NULL£¬Ôò·µ»ØÖ¸¶¨µÄÌæ»»Öµ£»²»È»£¬·µ»Ø±í´ïʽ×Ô¼º¡£
Óï·¨£º
ISNULL(expression, replacement_value)
µÇ¼ºó¸´ÖÆ
²ÎÊý£º
expression£ºÒª¼ì²éµÄ±í´ïʽ¡£
replacement_value£ºÈôÊÇ expression Ϊ NULL£¬Ôò·µ»ØµÄÌæ»»Öµ¡£
ÓÃ;£º
ISNULL º¯ÊýÖ÷ÒªÓÃÓÚ´¦Àí NULL Öµ£¬±ÜÃâ·ºÆðÊý¾ÝÍêÕûÐÔÎÊÌâ¡£ÒÔÏÂÊÇ ISNULL º¯ÊýµÄ³£¼ûÓÃ;£º
Ìæ»» NULL ֵΪ·Ç NULL Öµ£ºISNULL º¯Êý¿ÉÒÔ½« NULL ÖµÌ滻ΪԤ½ç˵µÄ·Ç NULL Öµ£¬È·±£Êý¾ÝÍêÕûÐÔ¡£
×èÖ¹Êý¾Ýת»»¹ýʧ£ºÔÚijЩÇéÐÎÏ£¬NULL ÖµÎÞ·¨×ª»»ÎªÆäËûÊý¾ÝÀàÐÍ£¬ÀýÈçÔÚ¾ÙÐÐÊýѧÔËËãʱ¡£ISNULL º¯Êý¿ÉÒÔ½« NULL ÖµÌ滻Ϊ 0 µÈռλ·û£¬´Ó¶ø×èֹת»»¹ýʧ¡£
ÏÔʾÓÐÒâÒåµÄÖµ£º¹ØÓÚijЩ±¨±í»òÓ¦ÓóÌÐò£¬ÏÔʾ NULL Öµ¿ÉÄܲ»¶ÔÊÊ»ò²»Àû±ã¡£ISNULL º¯Êý¿ÉÒÔ½« NULL ÖµÌ滻Ϊ¸ü¾ßÒâÒåµÄÎı¾»òÊý×Ö£¬ÀýÈç “Î´Öª” »ò “-1″¡£
ʾÀý£º
ÒÔÏÂʾÀý½«Îª NULL µÄ Name ÁÐÌ滻Ϊ “Unknown”£º
SELECT ISNULL(Name, 'Unknown') AS Name FROM table_name;
µÇ¼ºó¸´ÖÆ
ÒÔÏÂʾÀý½«Îª NULL µÄ Amount ÁÐÌ滻Ϊ 0£º
SELECT ISNULL(Amount, 0) AS Amount FROM table_name;
µÇ¼ºó¸´ÖÆ
×¢ÖØ£º
ISNULL º¯Êý½öÊÊÓÃÓÚµ¥¸ö±í´ïʽ¡£ÈôÊDZí´ïʽ°üÀ¨×ÓÅÌÎÊ»ò JOIN£¬Ôò¿ÉÄÜÐèҪʹÓÃÆäËûº¯Êý£¨ÀýÈç COALESCE£©¡£
ISNULL º¯ÊýµÄÌæ»»Öµ¿ÉÒÔÊÇÈκÎÊý¾ÝÀàÐÍ¡£
ÈôÊDZí´ïʽΪ·Ç NULL£¬Ôò ISNULL º¯Êý½«ÔÑù·µ»Ø¸Ã±í´ïʽ¡£
ÒÔÉϾÍÊÇsqlÖÐisnullÊÇʲôÒâ˼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡