{"id":187612,"date":"2024-11-11T15:43:19","date_gmt":"2024-11-11T07:43:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/187612\/"},"modified":"2024-11-11T15:43:20","modified_gmt":"2024-11-11T07:43:20","slug":"%e6%95%b8%e6%93%9a%e5%ba%ab%e8%aa%9e%e5%8f%a5%e4%b8%ad%e7%a9%ba%e5%80%bc%e7%9a%84%e8%99%95%e7%90%86%e6%96%b9%e5%bc%8f-%e6%95%b8%e6%93%9a%e5%ba%ab%e8%aa%9e%e5%8f%a5null%e5%80%bc","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/187612\/","title":{"rendered":"\u6578\u64da\u5eab\u8a9e\u53e5\u4e2d\u7a7a\u503c\u7684\u8655\u7406\u65b9\u5f0f (\u6578\u64da\u5eab\u8a9e\u53e5null\u503c)"},"content":{"rendered":"<h1 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e8%aa%9e%e5%8f%a5%e4%b8%ad%e7%a9%ba%e5%80%bc%e7%9a%84%e8%99%95%e7%90%86%e6%96%b9%e5%bc%8f-%e6%95%b8%e6%93%9a%e5%ba%ab%e8%aa%9e%e5%8f%a5null%e5%80%bc-cQXyDmSgrS\">\u6578\u64da\u5eab\u8a9e\u53e5\u4e2d\u7a7a\u503c\u7684\u8655\u7406\u65b9\u5f0f (\u6578\u64da\u5eab\u8a9e\u53e5null\u503c)<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\u4e2d\uff0c\u7a7a\u503c\uff08NULL\uff09\u662f\u4e00\u500b\u91cd\u8981\u7684\u6982\u5ff5\u3002\u5b83\u8868\u793a\u4e00\u500b\u7f3a\u5931\u7684\u6216\u672a\u77e5\u7684\u6578\u64da\u503c\u3002\u5c0d\u65bc\u958b\u767c\u8005\u548c\u6578\u64da\u5eab\u7ba1\u7406\u54e1\u4f86\u8aaa\uff0c\u6b63\u78ba\u8655\u7406\u7a7a\u503c\u662f\u78ba\u4fdd\u6578\u64da\u5b8c\u6574\u6027\u548c\u6e96\u78ba\u6027\u7684\u95dc\u9375\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u6578\u64da\u5eab\u8a9e\u53e5\u4e2d\u7a7a\u503c\u7684\u8655\u7406\u65b9\u5f0f\uff0c\u5305\u62ec\u5982\u4f55\u63d2\u5165\u3001\u67e5\u8a62\u548c\u66f4\u65b0\u7a7a\u503c\uff0c\u4ee5\u53ca\u5728\u4e0d\u540c\u6578\u64da\u5eab\u7cfb\u7d71\u4e2d\u7684\u5177\u9ad4\u5be6\u73fe\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e7%a9%ba%e5%80%bc%ef%bc%88null%ef%bc%89%ef%bc%9f-cQXyDmSgrS\">\u4ec0\u9ebc\u662f\u7a7a\u503c\uff08NULL\uff09\uff1f<\/h2>\n<p>\u7a7a\u503c\uff08NULL\uff09\u4e26\u4e0d\u7b49\u540c\u65bc\u96f6\uff080\uff09\u6216\u7a7a\u5b57\u7b26\u4e32\uff08&#8221;&#8221;\uff09\u3002\u5b83\u8868\u793a\u4e00\u500b\u7f3a\u5931\u7684\u503c\uff0c\u901a\u5e38\u7528\u65bc\u8868\u793a\u6578\u64da\u7684\u7f3a\u5931\u6216\u672a\u77e5\u3002\u4f8b\u5982\uff0c\u5728\u4e00\u500b\u7528\u6236\u8cc7\u6599\u8868\u4e2d\uff0c\u5982\u679c\u67d0\u500b\u7528\u6236\u7684\u96fb\u8a71\u865f\u78bc\u5c1a\u672a\u63d0\u4f9b\uff0c\u5247\u8a72\u5b57\u6bb5\u53ef\u4ee5\u8a2d\u7f6e\u70baNULL\u3002<\/p>\n<h2 id=\"%e6%8f%92%e5%85%a5%e7%a9%ba%e5%80%bc-cQXyDmSgrS\">\u63d2\u5165\u7a7a\u503c<\/h2>\n<p>\u5728\u63d2\u5165\u6578\u64da\u6642\uff0c\u53ef\u4ee5\u660e\u78ba\u5730\u5c07\u67d0\u500b\u5b57\u6bb5\u8a2d\u7f6e\u70baNULL\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528SQL\u8a9e\u53e5\u63d2\u5165\u7a7a\u503c\u7684\u7bc4\u4f8b\uff1a<\/p>\n<pre><code>INSERT INTO users (username, email, phone) VALUES ('john_doe', 'john@example.com', NULL);<\/code><\/pre>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u96fb\u8a71\u865f\u78bc\u5b57\u6bb5\u88ab\u8a2d\u7f6e\u70baNULL\uff0c\u8868\u793a\u8a72\u7528\u6236\u5c1a\u672a\u63d0\u4f9b\u96fb\u8a71\u865f\u78bc\u3002<\/p>\n<h2 id=\"%e6%9f%a5%e8%a9%a2%e7%a9%ba%e5%80%bc-cQXyDmSgrS\">\u67e5\u8a62\u7a7a\u503c<\/h2>\n<p>\u67e5\u8a62\u7a7a\u503c\u6642\uff0c\u5fc5\u9808\u4f7f\u7528\u7279\u5b9a\u7684\u8a9e\u6cd5\u3002\u5927\u591a\u6578\u6578\u64da\u5eab\u7cfb\u7d71\u4f7f\u7528IS NULL\u6216IS NOT NULL\u4f86\u6aa2\u67e5\u7a7a\u503c\u3002\u4ee5\u4e0b\u662f\u67e5\u8a62\u7a7a\u503c\u7684\u7bc4\u4f8b\uff1a<\/p>\n<pre><code>SELECT * FROM users WHERE phone IS NULL;<\/code><\/pre>\n<p>\u9019\u689d\u8a9e\u53e5\u5c07\u8fd4\u56de\u6240\u6709\u96fb\u8a71\u865f\u78bc\u70baNULL\u7684\u7528\u6236\u3002<\/p>\n<h2 id=\"%e6%9b%b4%e6%96%b0%e7%a9%ba%e5%80%bc-cQXyDmSgrS\">\u66f4\u65b0\u7a7a\u503c<\/h2>\n<p>\u5728\u66f4\u65b0\u6578\u64da\u6642\uff0c\u4e5f\u53ef\u4ee5\u5c07\u67d0\u500b\u5b57\u6bb5\u8a2d\u7f6e\u70baNULL\u3002\u4ee5\u4e0b\u662f\u66f4\u65b0\u7a7a\u503c\u7684\u7bc4\u4f8b\uff1a<\/p>\n<pre><code>UPDATE users SET phone = NULL WHERE username = 'john_doe';<\/code><\/pre>\n<p>\u9019\u689d\u8a9e\u53e5\u5c07\u7528\u6236\u201cjohn_doe\u201d\u7684\u96fb\u8a71\u865f\u78bc\u8a2d\u7f6e\u70baNULL\u3002<\/p>\n<h2 id=\"%e7%a9%ba%e5%80%bc%e7%9a%84%e6%af%94%e8%bc%83-cQXyDmSgrS\">\u7a7a\u503c\u7684\u6bd4\u8f03<\/h2>\n<p>\u5728SQL\u4e2d\uff0c\u7a7a\u503c\u7684\u6bd4\u8f03\u662f\u7279\u6b8a\u7684\u3002\u4efb\u4f55\u8207NULL\u7684\u6bd4\u8f03\uff08\u4f8b\u5982=\u3001!=\uff09\u90fd\u6703\u8fd4\u56deNULL\uff0c\u800c\u4e0d\u662fTRUE\u6216FALSE\u3002\u56e0\u6b64\uff0c\u4f7f\u7528NULL\u6642\u9700\u8981\u7279\u5225\u5c0f\u5fc3\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>SELECT * FROM users WHERE phone = NULL; -- \u9019\u5c07\u4e0d\u6703\u8fd4\u56de\u4efb\u4f55\u7d50\u679c<\/code><\/pre>\n<p>\u6b63\u78ba\u7684\u505a\u6cd5\u662f\u4f7f\u7528IS NULL\u6216IS NOT NULL\u4f86\u9032\u884c\u6bd4\u8f03\u3002<\/p>\n<h2 id=\"%e4%b8%8d%e5%90%8c%e6%95%b8%e6%93%9a%e5%ba%ab%e7%b3%bb%e7%b5%b1%e4%b8%ad%e7%9a%84%e7%a9%ba%e5%80%bc%e8%99%95%e7%90%86-cQXyDmSgrS\">\u4e0d\u540c\u6578\u64da\u5eab\u7cfb\u7d71\u4e2d\u7684\u7a7a\u503c\u8655\u7406<\/h2>\n<p>\u4e0d\u540c\u7684\u6578\u64da\u5eab\u7cfb\u7d71\u5c0d\u7a7a\u503c\u7684\u8655\u7406\u53ef\u80fd\u6703\u6709\u6240\u4e0d\u540c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u6578\u64da\u5eab\u7cfb\u7d71\u7684\u7a7a\u503c\u8655\u7406\u65b9\u5f0f\uff1a<\/p>\n<ul>\n<li><strong>MySQL\uff1a<\/strong> MySQL\u652f\u6301NULL\u503c\uff0c\u4e26\u4e14\u53ef\u4ee5\u5728\u7d22\u5f15\u4e2d\u4f7f\u7528NULL\u3002<\/li>\n<li><strong>PostgreSQL\uff1a<\/strong> PostgreSQL\u4e5f\u652f\u6301NULL\uff0c\u4e26\u4e14\u63d0\u4f9b\u4e86\u591a\u7a2e\u51fd\u6578\u4f86\u8655\u7406NULL\u503c\u3002<\/li>\n<li><strong>SQL Server\uff1a<\/strong> SQL Server\u5141\u8a31NULL\u503c\uff0c\u4e26\u4e14\u63d0\u4f9b\u4e86ISNULL\u51fd\u6578\u4f86\u8655\u7406NULL\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-cQXyDmSgrS\">\u7d50\u8ad6<\/h2>\n<p>\u5728\u6578\u64da\u5eab\u8a9e\u53e5\u4e2d\uff0c\u6b63\u78ba\u8655\u7406\u7a7a\u503c\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u7121\u8ad6\u662f\u5728\u63d2\u5165\u3001\u67e5\u8a62\u9084\u662f\u66f4\u65b0\u6578\u64da\u6642\uff0c\u958b\u767c\u8005\u90fd\u61c9\u8a72\u6e05\u695a\u5982\u4f55\u4f7f\u7528NULL\uff0c\u4e26\u4e86\u89e3\u4e0d\u540c\u6578\u64da\u5eab\u7cfb\u7d71\u7684\u7279\u6027\u3002\u901a\u904e\u6b63\u78ba\u7684\u7a7a\u503c\u8655\u7406\uff0c\u53ef\u4ee5\u63d0\u9ad8\u6578\u64da\u7684\u5b8c\u6574\u6027\u548c\u6e96\u78ba\u6027\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u670d\u52d9\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u6578\u64da\u5eab\u8a9e\u53e5\u4e2d\u7a7a\u503c\u7684\u8655\u7406\u65b9\u5f0f\uff0c\u638c\u63e1\u5982\u4f55\u6709\u6548\u7ba1\u7406\u548c\u67e5\u8a62null\u503c\uff0c\u63d0\u5347\u6578\u64da\u5eab\u64cd\u4f5c\u6548\u7387\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-187612","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/187612","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=187612"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/187612\/revisions"}],"predecessor-version":[{"id":187613,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/187612\/revisions\/187613"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=187612"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=187612"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=187612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}