sqlÖпÕÖµºÍnullµÄÇø±ð
ÔÚ sql ÖУ¬null ÌåÏÖδ֪Êý¾Ý£¬¶ø¿ÕÖµ´ú±íδ·ÖÅÉÖµ¡£null ºÍ¿ÕÖµµÄ²î±ðÔÚÓÚÓïÒå¼ÄÒ壨null ΪÃ÷ȷȱʧ£¬¿ÕÖµÎÞÐèÓïÒ壩¡¢ÐÔÄÜЧÂÊ£¨null ´¦ÀíЧÂʸü¸ß£©ºÍÅÌÎÊЧ¹û£¨null ½ÏÁ¿Ð§¹û²»¿ÉÕ¹Íû£©¡£Í¨¹ý is null¡¢is not null »ò coalesce ÅÐ¶Ï null ºÍ¿ÕÖµ¡£×î¼Ñʵ¼ùÊÇÃ÷ȷʹÓà null ÌåÏÖȱʧÊý¾Ý£¬×èֹʹÓÿÕÖµ£¬²¢Ã÷ÖÇ´¦Àí null Öµ¡£
SQL ÖÐ NULL ºÍ¿ÕÖµµÄÇø±ð
ÔÚ SQL ÖУ¬NULL ºÍ¿ÕÖµÊDzî±ðµÄ¿´·¨¡£
¿ÕÖµÊÇÖ¸Ò»¸öÉÐδ·ÖÅÉÖµµÄ×ֶλòÁС£µ±´Ó±íÖмìË÷Êý¾Ýʱ£¬¿ÕÖµÒÔÌض¨·½·¨ÏÔʾ£¬Ïêϸȡ¾öÓÚÊý¾Ý¿âÖÎÀíϵͳ (DBMS)¡£ÀýÈ磬ÔÚ MySQL ÖУ¬¿ÕÖµÏÔʾΪ¿Õ×Ö·û´®¡¢0 »ò NULL£¬Ïêϸȡ¾öÓÚ×ֶεÄÊý¾ÝÀàÐÍ¡£
NULLÊÇÒ»¸öÌØÊâÖµ£¬Ã÷È·ÌåÏÖ¸Ã×ֶεÄֵδ֪»ò²»±£´æ¡£ËüÓë¿ÕÖµµÄ²î±ðÖ®´¦ÔÚÓÚ£¬ËüָʾµÄÊÇÊý¾ÝÖеÄÏÖʵȱʧ£¬¶ø²»ÊÇÉÐδ·ÖÅÉÖµ¡£
²î±ðµÄ¼ÄÒå
NULL ºÍ¿ÕÖµÖ®¼äµÄ²î±ð¾ßÓÐÖ÷ÒªÒâÒ壺
Êý¾ÝÍêÕûÐÔ£ºNULL ÓÃÓÚÌåÏÖȱʧ»òδ֪µÄÊý¾Ý£¬¶ø¿ÕÖµ²»ÐèÒªÈκÎÓïÒå¡£
ÐÔÄÜ£ºÄ³Ð© DBMS ÔÚ´¦Àí NULL ֵʱ±È´¦Àí¿ÕֵʱЧÂʸü¸ß¡£
ÅÌÎÊЧ¹û£º½« NULL ÖµÓëÆäËûÖµ¾ÙÐнÏÁ¿Ê±£¬Ð§¹û¿ÉÄÜÎÞ·¨Õ¹Íû¡£
ÅÐ¶Ï NULL ºÍ¿ÕÖµ
ÔÚ SQL ÖУ¬¿ÉÒÔͨ¹ýÒÔÏÂÒªÁìÀ´ÅжÏÒ»¸öÖµÊÇ NULL ÕվɿÕÖµ£º
IS NULL£º·µ»ØÒ»¸ö²¼¶ûÖµ£¬Ö¸Ê¾¸ÃÖµÊÇ·ñΪ NULL¡£
IS NOT NULL£º·µ»ØÒ»¸ö²¼¶ûÖµ£¬Ö¸Ê¾¸ÃÖµÊÇ·ñ²»Îª NULL¡£
COALESCE£º·µ»ØµÚÒ»¸ö·Ç NULL Öµ£¬ÈôÊÇËùÓÐÖµ¶¼Îª NULL£¬Ôò·µ»ØÖ¸¶¨µÄĬÈÏÖµ¡£
×î¼Ñʵ¼ù
ÔÚ SQL ÖÐʹÓà NULL ºÍ¿Õֵʱ£¬Ó¦×ñÕÕÒÔÏÂ×î¼Ñʵ¼ù£º
Ã÷ȷʹÓà NULL À´ÌåÏÖȱʧ»òδ֪µÄÊý¾Ý¡£
×èֹʹÓÿÕÖµ£¬ÓÉÓÚËü¿ÉÄܻᵼÖÂÊý¾ÝÍêÕûÐÔÎÊÌâ¡£
ÔÚÅÌÎÊÖÐÃ÷Öǵش¦Àí NULL Öµ£¬Ë¼Á¿Ê¹Óà IS NULL¡¢IS NOT NULL »ò COALESCE º¯Êý¡£
ÒÔÉϾÍÊÇsqlÖпÕÖµºÍnullµÄÇø±ðµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡