{"id":6381,"date":"2024-11-14T09:33:54","date_gmt":"2024-11-14T01:33:54","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6381\/"},"modified":"2024-11-14T09:33:54","modified_gmt":"2024-11-14T01:33:54","slug":"mysql-ifnull%e8%83%bd%e5%88%a4%e6%96%ad%e7%a9%ba%e4%b8%b2%e4%b9%88","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6381\/","title":{"rendered":"mysql ifnull\u80fd\u5224\u65ad\u7a7a\u4e32\u4e48"},"content":{"rendered":"<blockquote><p>\n  \u5426\uff0cmysql ifnull \u51fd\u6570\u65e0\u6cd5\u5224\u65ad\u7a7a\u4e32\u3002\u5b83\u53ea\u80fd\u5224\u65ad null \u503c\uff0c\u800c\u7a7a\u4e32\u662f\u4e00\u4e2a\u957f\u5ea6\u4e3a 0 \u7684\u5b57\u7b26\u4e32\uff0c\u5728 mysql \u4e2d\u8868\u793a\u4e3a &#8221;\u3002\u8981\u5224\u65ad\u7a7a\u4e32\uff0c\u53ef\u4ee5\u4f7f\u7528 isnull() \u6216 isempty() \u51fd\u6570\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/01\/2024080106214814177.jpg\" class=\"aligncenter\" title=\"mysql ifnull\u80fd\u5224\u65ad\u7a7a\u4e32\u4e48\u63d2\u56fe\" alt=\"mysql ifnull\u80fd\u5224\u65ad\u7a7a\u4e32\u4e48\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL IFNULL \u51fd\u6570\u80fd\u5426\u5224\u65ad\u7a7a\u4e32<\/strong><\/p>\n<p><strong>\u7b80\u7b54\uff1a<\/strong><\/p>\n<p>\u5426\uff0cMySQL IFNULL \u51fd\u6570\u65e0\u6cd5\u5224\u65ad\u7a7a\u4e32\u3002<\/p>\n<p><strong>\u8be6\u7ec6\u89e3\u7b54\uff1a<\/strong><\/p>\n<p>MySQL IFNULL \u51fd\u6570\u7528\u4e8e\u5c06 NULL \u503c\u66ff\u6362\u4e3a\u6307\u5b9a\u7684\u9ed8\u8ba4\u503c\u3002\u5176\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>IFNULL(expr1, expr2)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>expr1\uff1a\u8981\u68c0\u67e5\u7684\u503c<\/li>\n<li>expr2\uff1a\u5982\u679c expr1 \u4e3a NULL \u5219\u8fd4\u56de\u7684\u9ed8\u8ba4\u503c<\/li>\n<\/ul>\n<p>IFNULL \u51fd\u6570\u53ea\u80fd\u5224\u65ad NULL \u503c\uff0c\u65e0\u6cd5\u5224\u65ad\u7a7a\u4e32\u3002\u7a7a\u4e32\u662f\u4e00\u4e2a\u957f\u5ea6\u4e3a 0 \u7684\u5b57\u7b26\u4e32\uff0c\u5728 MySQL \u4e2d\u8868\u793a\u4e3a &#8221;\u3002\u56e0\u6b64\uff0c\u5982\u679c expr1 \u4e3a\u7a7a\u4e32\uff0cIFNULL \u51fd\u6570\u5c06\u65e0\u6cd5\u5c06\u5176\u66ff\u6362\u4e3a\u9ed8\u8ba4\u503c\u3002<\/p>\n<p>\u8981\u5224\u65ad\u7a7a\u4e32\uff0c\u53ef\u4ee5\u4f7f\u7528 ISNULL() \u6216 ISEMPTY() \u51fd\u6570\u3002\u8fd9\u4e24\u4e2a\u51fd\u6570\u90fd\u8fd4\u56de\u4e00\u4e2a\u5e03\u5c14\u503c\uff0c\u6307\u793a expr1 \u662f\u5426\u4e3a\u7a7a\u4e32\u3002<\/p>\n<ul>\n<li>ISNULL() \u51fd\u6570\u68c0\u67e5 expr1 \u662f\u5426\u4e3a NULL \u6216\u7a7a\u4e32\u3002<\/li>\n<li>ISEMPTY() \u51fd\u6570\u4ec5\u68c0\u67e5 expr1 \u662f\u5426\u4e3a\u7a7a\u4e32\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff0c\u4ee5\u4e0b\u67e5\u8be2\u4f7f\u7528 ISNULL() \u51fd\u6570\u68c0\u67e5\u540d\u4e3a &#8220;name&#8221; \u7684\u5217\u662f\u5426\u4e3a NULL \u6216\u7a7a\u4e32\uff1a<\/p>\n<pre>SELECT CASE\n    WHEN ISNULL(name) THEN 'NULL or empty'\n    ELSE name\nEND AS name_status\nFROM table_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f ifnull\u80fd\u5224\u65ad\u7a7a\u4e32\u4e48\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5426\uff0cmysql ifnull \u51fd\u6570\u65e0\u6cd5\u5224\u65ad\u7a7a\u4e32\u3002\u5b83\u53ea\u80fd\u5224\u65ad null \u503c\uff0c\u800c\u7a7a\u4e32\u662f\u4e00\u4e2a\u957f\u5ea6\u4e3a 0 \u7684\u5b57\u7b26\u4e32\uff0c\u5728 mysql \u4e2d\u8868\u793a\u4e3a &#8221;\u3002\u8981\u5224\u65ad\u7a7a\u4e32\uff0c\u53ef\u4ee5\u4f7f\u7528 isnull() \u6216 isempty() \u51fd\u6570\u3002 MySQL IFNULL \u51fd\u6570\u80fd\u5426\u5224\u65ad\u7a7a\u4e32 \u7b80\u7b54\uff1a \u5426\uff0cMySQL IFNULL \u51fd\u6570\u65e0\u6cd5\u5224\u65ad\u7a7a\u4e32\u3002 \u8be6\u7ec6\u89e3\u7b54\uff1a MySQL IFNULL \u51fd\u6570\u7528\u4e8e\u5c06 NULL \u503c\u66ff\u6362\u4e3a\u6307\u5b9a\u7684\u9ed8\u8ba4\u503c\u3002\u5176\u8bed\u6cd5\u5982\u4e0b\uff1a IFNULL(expr1, expr2) \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a expr1\uff1a\u8981\u68c0\u67e5\u7684\u503c expr2\uff1a\u5982\u679c expr1 \u4e3a NULL \u5219\u8fd4\u56de\u7684\u9ed8\u8ba4\u503c IFNULL \u51fd\u6570\u53ea\u80fd\u5224\u65ad NULL \u503c\uff0c\u65e0\u6cd5\u5224\u65ad\u7a7a\u4e32\u3002\u7a7a\u4e32\u662f\u4e00\u4e2a\u957f\u5ea6\u4e3a 0 \u7684\u5b57\u7b26\u4e32\uff0c\u5728 MySQL \u4e2d\u8868\u793a\u4e3a &#8221;\u3002\u56e0\u6b64\uff0c\u5982\u679c expr1 \u4e3a\u7a7a\u4e32\uff0cIFNULL \u51fd\u6570\u5c06\u65e0\u6cd5\u5c06\u5176\u66ff\u6362\u4e3a\u9ed8\u8ba4\u503c\u3002 \u8981\u5224\u65ad\u7a7a\u4e32\uff0c\u53ef\u4ee5\u4f7f\u7528 ISNULL() \u6216 ISEMPTY() \u51fd\u6570\u3002\u8fd9\u4e24\u4e2a\u51fd\u6570\u90fd\u8fd4\u56de\u4e00\u4e2a\u5e03\u5c14\u503c\uff0c\u6307\u793a expr1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-6381","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6381","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=6381"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6381\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}