{"id":179486,"date":"2024-11-09T02:13:21","date_gmt":"2024-11-08T18:13:21","guid":{"rendered":"https:\/\/server.hk\/cnblog\/179486\/"},"modified":"2024-11-09T02:13:22","modified_gmt":"2024-11-08T18:13:22","slug":"%e5%a6%82%e4%bd%95%e6%9c%89%e6%95%88%e5%9c%b0%e5%88%a4%e6%96%b7%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%ad%e7%9a%84%e6%95%b8%e6%93%9a%e6%98%af%e5%90%a6%e7%82%ba%e7%a9%ba%ef%bc%9f-%e6%95%b8%e6%93%9a%e5%ba%ab","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/179486\/","title":{"rendered":"\u5982\u4f55\u6709\u6548\u5730\u5224\u65b7\u6578\u64da\u5eab\u4e2d\u7684\u6578\u64da\u662f\u5426\u70ba\u7a7a\uff1f (\u6578\u64da\u5eab \u5224\u65b7\u70ba\u7a7a)"},"content":{"rendered":"<h1 id=\"%e5%a6%82%e4%bd%95%e6%9c%89%e6%95%88%e5%9c%b0%e5%88%a4%e6%96%b7%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%ad%e7%9a%84%e6%95%b8%e6%93%9a%e6%98%af%e5%90%a6%e7%82%ba%e7%a9%ba%ef%bc%9f-qlWBTIrdWx\">\u5982\u4f55\u6709\u6548\u5730\u5224\u65b7\u6578\u64da\u5eab\u4e2d\u7684\u6578\u64da\u662f\u5426\u70ba\u7a7a\uff1f<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u4e2d\uff0c\u5224\u65b7\u6578\u64da\u662f\u5426\u70ba\u7a7a\u662f\u4e00\u500b\u57fa\u672c\u800c\u91cd\u8981\u7684\u4efb\u52d9\u3002\u7121\u8ad6\u662f\u9032\u884c\u6578\u64da\u67e5\u8a62\u3001\u6578\u64da\u5206\u6790\u9084\u662f\u6578\u64da\u8655\u7406\uff0c\u78ba\u4fdd\u6578\u64da\u7684\u5b8c\u6574\u6027\u548c\u6709\u6548\u6027\u90fd\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u6709\u6548\u5730\u5224\u65b7\u6578\u64da\u5eab\u4e2d\u7684\u6578\u64da\u662f\u5426\u70ba\u7a7a\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u793a\u4f8b\u548c\u4ee3\u78bc\u7247\u6bb5\u3002<\/p>\n<h2 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%ad%e7%9a%84%e7%a9%ba%e6%95%b8%e6%93%9a%e5%ae%9a%e7%be%a9-qlWBTIrdWx\">\u6578\u64da\u5eab\u4e2d\u7684\u7a7a\u6578\u64da\u5b9a\u7fa9<\/h2>\n<p>\u5728\u6578\u64da\u5eab\u4e2d\uff0c\u7a7a\u6578\u64da\u901a\u5e38\u6307\u7684\u662f\u6c92\u6709\u4efb\u4f55\u6709\u6548\u503c\u7684\u6578\u64da\u3002\u9019\u53ef\u4ee5\u662f\u4ee5\u4e0b\u5e7e\u7a2e\u60c5\u6cc1\uff1a<\/p>\n<ul>\n<li>\u5b57\u6bb5\u7684\u503c\u70ba <code>NULL<\/code>\u3002<\/li>\n<li>\u5b57\u6bb5\u7684\u503c\u70ba\u7a7a\u5b57\u7b26\u4e32 <code>''<\/code>\u3002<\/li>\n<li>\u5b57\u6bb5\u7684\u503c\u70ba\u7279\u5b9a\u7684\u4f54\u4f4d\u7b26\uff0c\u5982 <code>'N\/A'<\/code> \u6216 <code>'\u7121\u8cc7\u6599'<\/code>\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%88%a4%e6%96%b7%e6%95%b8%e6%93%9a%e6%98%af%e5%90%a6%e7%82%ba%e7%a9%ba%e7%9a%84%e6%96%b9%e6%b3%95-qlWBTIrdWx\">\u5224\u65b7\u6578\u64da\u662f\u5426\u70ba\u7a7a\u7684\u65b9\u6cd5<\/h2>\n<p>\u5728\u4e0d\u540c\u7684\u6578\u64da\u5eab\u7cfb\u7d71\u4e2d\uff0c\u5224\u65b7\u6578\u64da\u662f\u5426\u70ba\u7a7a\u7684\u65b9\u6cd5\u53ef\u80fd\u6703\u6709\u6240\u4e0d\u540c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u6578\u64da\u5eab\u7cfb\u7d71\u53ca\u5176\u5224\u65b7\u7a7a\u6578\u64da\u7684\u65b9\u5f0f\uff1a<\/p>\n<h3 id=\"1-mysql-qlWBTIrdWx\">1. MySQL<\/h3>\n<p>\u5728 MySQL \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>IS NULL<\/code> \u548c <code>='' <\/code> \u4f86\u5224\u65b7\u6578\u64da\u662f\u5426\u70ba\u7a7a\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>SELECT * FROM users WHERE username IS NULL OR username = '';<\/code><\/pre>\n<h3 id=\"2-postgresql-qlWBTIrdWx\">2. PostgreSQL<\/h3>\n<p>\u5728 PostgreSQL \u4e2d\uff0c\u5224\u65b7\u7a7a\u6578\u64da\u7684\u65b9\u5f0f\u8207 MySQL \u985e\u4f3c\u3002\u53ef\u4ee5\u4f7f\u7528 <code>IS NULL<\/code> \u4f86\u6aa2\u67e5\u5b57\u6bb5\u662f\u5426\u70ba\u7a7a\uff1a<\/p>\n<pre><code>SELECT * FROM users WHERE username IS NULL OR username = '';<\/code><\/pre>\n<h3 id=\"3-sql-server-qlWBTIrdWx\">3. SQL Server<\/h3>\n<p>\u5728 SQL Server \u4e2d\uff0c\u4f7f\u7528 <code>IS NULL<\/code> \u548c <code>LEN()<\/code> \u51fd\u6578\u4f86\u5224\u65b7\u6578\u64da\u662f\u5426\u70ba\u7a7a\u3002\u4ee5\u4e0b\u662f\u793a\u4f8b\uff1a<\/p>\n<pre><code>SELECT * FROM users WHERE username IS NULL OR LEN(username) = 0;<\/code><\/pre>\n<h2 id=\"%e4%bd%bf%e7%94%a8%e5%87%bd%e6%95%b8%e9%80%b2%e8%a1%8c%e7%a9%ba%e5%80%bc%e6%aa%a2%e6%9f%a5-qlWBTIrdWx\">\u4f7f\u7528\u51fd\u6578\u9032\u884c\u7a7a\u503c\u6aa2\u67e5<\/h2>\n<p>\u8a31\u591a\u6578\u64da\u5eab\u7cfb\u7d71\u63d0\u4f9b\u4e86\u5167\u5efa\u51fd\u6578\u4f86\u5e6b\u52a9\u6aa2\u67e5\u7a7a\u503c\u3002\u4f8b\u5982\uff0c\u5728 MySQL \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>IFNULL()<\/code> \u51fd\u6578\u4f86\u66ff\u63db\u7a7a\u503c\uff1a<\/p>\n<pre><code>SELECT IFNULL(username, '\u7121\u8cc7\u6599') AS username FROM users;<\/code><\/pre>\n<p>\u5728 PostgreSQL \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>COALESCE()<\/code> \u51fd\u6578\u4f86\u5be6\u73fe\u76f8\u4f3c\u7684\u529f\u80fd\uff1a<\/p>\n<pre><code>SELECT COALESCE(username, '\u7121\u8cc7\u6599') AS username FROM users;<\/code><\/pre>\n<h2 id=\"%e6%9c%80%e4%bd%b3%e5%af%a6%e8%b8%90-qlWBTIrdWx\">\u6700\u4f73\u5be6\u8e10<\/h2>\n<p>\u5728\u9032\u884c\u6578\u64da\u5eab\u64cd\u4f5c\u6642\uff0c\u9075\u5faa\u4e00\u4e9b\u6700\u4f73\u5be6\u8e10\u53ef\u4ee5\u5e6b\u52a9\u63d0\u9ad8\u6578\u64da\u7684\u5b8c\u6574\u6027\u548c\u6e96\u78ba\u6027\uff1a<\/p>\n<ul>\n<li>\u5728\u8a2d\u8a08\u6578\u64da\u5eab\u6642\uff0c\u8003\u616e\u4f7f\u7528\u9069\u7576\u7684\u7d04\u675f\u689d\u4ef6\uff0c\u4f8b\u5982 <code>NOT NULL<\/code>\u3002<\/li>\n<li>\u5b9a\u671f\u6aa2\u67e5\u6578\u64da\u5eab\u4e2d\u7684\u7a7a\u503c\uff0c\u4e26\u9032\u884c\u5fc5\u8981\u7684\u6e05\u7406\u3002<\/li>\n<li>\u5728\u61c9\u7528\u5c64\u9762\u4e0a\uff0c\u5c0d\u7528\u6236\u8f38\u5165\u9032\u884c\u9a57\u8b49\uff0c\u907f\u514d\u5c07\u7a7a\u503c\u5beb\u5165\u6578\u64da\u5eab\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-qlWBTIrdWx\">\u7d50\u8ad6<\/h2>\n<p>\u6709\u6548\u5730\u5224\u65b7\u6578\u64da\u5eab\u4e2d\u7684\u6578\u64da\u662f\u5426\u70ba\u7a7a\u662f\u6578\u64da\u7ba1\u7406\u4e2d\u7684\u4e00\u500b\u91cd\u8981\u65b9\u9762\u3002\u901a\u904e\u4f7f\u7528\u9069\u7576\u7684\u67e5\u8a62\u8a9e\u53e5\u548c\u51fd\u6578\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u78ba\u4fdd\u6578\u64da\u7684\u5b8c\u6574\u6027\u548c\u6e96\u78ba\u6027\u3002\u7121\u8ad6\u662f\u4f7f\u7528 MySQL\u3001PostgreSQL \u9084\u662f SQL Server\uff0c\u4e86\u89e3\u5982\u4f55\u6aa2\u67e5\u7a7a\u503c\u90fd\u80fd\u5e6b\u52a9\u63d0\u5347\u6578\u64da\u5eab\u7684\u6027\u80fd\u548c\u53ef\u9760\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\u4f86\u7ba1\u7406\u60a8\u7684\u6578\u64da\u5eab\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u7684\u5ba2\u6236\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>\u5b78\u7fd2\u5982\u4f55\u6709\u6548\u5224\u65b7\u6578\u64da\u5eab\u4e2d\u7684\u6578\u64da\u662f\u5426\u70ba\u7a7a\uff0c\u638c\u63e1\u67e5\u8a62\u6280\u5de7\u8207\u6700\u4f73\u5be6\u8e10\uff0c\u63d0\u5347\u6578\u64da\u7ba1\u7406\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-179486","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/179486","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=179486"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/179486\/revisions"}],"predecessor-version":[{"id":179487,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/179486\/revisions\/179487"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=179486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=179486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=179486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}