SQL NULL Öµ

NULL ÖµÊÇÒÅ©µÄδ֪Êý¾Ý¡£

ĬÈϵأ¬±íµÄÁпÉÒÔ´æ·Å NULL Öµ¡£

±¾Õ½²½â IS NULL ºÍ IS NOT NULL ²Ù×÷·û¡£

SQL NULL Öµ

Èç¹û±íÖеÄij¸öÁÐÊÇ¿ÉÑ¡µÄ£¬ÄÇôÎÒÃÇ¿ÉÒÔÔÚ²»Ïò¸ÃÁÐÌí¼ÓÖµµÄÇé¿öϲåÈëмͼ»ò¸üÐÂÒÑÓеļǼ¡£ÕâÒâζןÃ×ֶν«ÒÔ NULL Öµ±£´æ¡£

NULL ÖµµÄ´¦Àí·½Ê½ÓëÆäËûÖµ²»Í¬¡£

NULL ÓÃ×÷δ֪µÄ»ò²»ÊÊÓõÄÖµµÄռλ·û¡£

×¢ÊÍ£ºÎÞ·¨±È½Ï NULL ºÍ 0£»ËüÃÇÊDz»µÈ¼ÛµÄ¡£

SQL µÄ NULL Öµ´¦Àí

Çë¿´ÏÂÃæµÄ "Persons" ±í£º

Id LastName FirstName Address City
1 Adams John   London
2 Bush George Fifth Avenue New York
3 Carter Thomas   Beijing

¼ÙÈç "Persons" ±íÖÐµÄ "Address" ÁÐÊÇ¿ÉÑ¡µÄ¡£ÕâÒâζ×ÅÈç¹ûÔÚ "Address" ÁвåÈëÒ»Ìõ²»´øÖµµÄ¼Ç¼£¬"Address" ÁлáʹÓà NULL Öµ±£´æ¡£

ÄÇôÎÒÃÇÈçºÎ²âÊÔ NULL ÖµÄØ£¿

ÎÞ·¨Ê¹ÓñȽÏÔËËã·ûÀ´²âÊÔ NULL Öµ£¬±ÈÈç =, <, »òÕß <>¡£

ÎÒÃDZØÐëʹÓà IS NULL ºÍ IS NOT NULL ²Ù×÷·û¡£

SQL IS NULL

ÎÒÃÇÈçºÎ½ö½öÑ¡È¡ÔÚ "Address" ÁÐÖдøÓÐ NULL ÖµµÄ¼Ç¼ÄØ£¿

ÎÒÃDZØÐëʹÓà IS NULL ²Ù×÷·û£º

SELECT LastName,FirstName,Address FROM Persons
WHERE Address IS NULL

½á¹û¼¯£º

LastName FirstName Address
Adams John  
Carter Thomas  

Ìáʾ£ºÇëʼÖÕʹÓà IS NULL À´²éÕÒ NULL Öµ¡£

SQL IS NOT NULL

ÎÒÃÇÈçºÎÑ¡È¡ÔÚ "Address" ÁÐÖв»´øÓÐ NULL ÖµµÄ¼Ç¼ÄØ£¿

ÎÒÃDZØÐëʹÓà IS NOT NULL ²Ù×÷·û£º

SELECT LastName,FirstName,Address FROM Persons
WHERE Address IS NOT NULL

½á¹û¼¯£º

LastName FirstName Address
Bush George Fifth Avenue

ÔÚÏÂÒ»½ÚÖУ¬ÎÒÃÇÁ˽â ISNULL()¡¢NVL()¡¢IFNULL() ºÍ COALESCE() º¯Êý¡£