{"id":5665,"date":"2024-11-14T09:17:10","date_gmt":"2024-11-14T01:17:10","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5665\/"},"modified":"2024-11-14T09:17:10","modified_gmt":"2024-11-14T01:17:10","slug":"sql%e5%ad%97%e7%ac%a6%e4%b8%b2%e9%95%bf%e5%ba%a6%e6%80%8e%e4%b9%88%e7%9c%8b","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5665\/","title":{"rendered":"sql\u5b57\u7b26\u4e32\u957f\u5ea6\u600e\u4e48\u770b"},"content":{"rendered":"<blockquote><p>\n  \u5728 sql \u4e2d\uff0c\u5b57\u7b26\u4e32\u957f\u5ea6\u6307\u5b57\u7b26\u4e32\u4e2d\u5b57\u7b26\u7684\u6570\u91cf\uff08\u4e0d\u542b\u7a7a\u683c\uff09\u3002length() \u51fd\u6570\u53ef\u83b7\u53d6\u5b57\u7b26\u4e32\u957f\u5ea6\uff0c\u8bed\u6cd5\u4e3a length(string)\u3002\u5982\u679c\u5b57\u7b26\u4e32\u4e3a null\uff0c\u4f7f\u7528 isnull() \u51fd\u6570\u66ff\u6362\u4e3a\u9ed8\u8ba4\u503c\uff0c\u5982 length(isnull(name, &#8216;n\/a&#8217;))\u3002\u9700\u8981\u6ce8\u610f length() \u51fd\u6570\u533a\u5206\u5927\u5c0f\u5199\u4e14\u4e0d\u8003\u8651 unicode \u5b57\u7b26\u7684\u5bbd\u5b57\u7b26\u8868\u793a\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/30\/2024053020125312272.jpg\" class=\"aligncenter\" title=\"sql\u5b57\u7b26\u4e32\u957f\u5ea6\u600e\u4e48\u770b\u63d2\u56fe\" alt=\"sql\u5b57\u7b26\u4e32\u957f\u5ea6\u600e\u4e48\u770b\u63d2\u56fe\" \/><\/p>\n<p><strong>SQL \u5b57\u7b26\u4e32\u957f\u5ea6<\/strong><\/p>\n<p><strong>\u5b57\u7b26\u4e32\u957f\u5ea6\u7684\u5b9a\u4e49<\/strong><\/p>\n<p>\u5728 SQL \u4e2d\uff0c\u5b57\u7b26\u4e32\u957f\u5ea6\u6307\u7684\u662f\u5b57\u7b26\u4e32\u4e2d\u5b57\u7b26\u7684\u6570\u91cf\uff0c\u4e0d\u5305\u62ec\u7a7a\u683c\u3002<\/p>\n<p><strong>\u83b7\u53d6\u5b57\u7b26\u4e32\u957f\u5ea6<\/strong><\/p>\n<p>\u83b7\u53d6\u5b57\u7b26\u4e32\u957f\u5ea6\u53ef\u4ee5\u4f7f\u7528 LENGTH() \u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u6536\u4e00\u4e2a\u5b57\u7b26\u4e32\u53c2\u6570\u5e76\u8fd4\u56de\u5176\u957f\u5ea6\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>LENGTH(string)<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>SELECT LENGTH('Hello World'); -- \u8fd4\u56de 11<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u5904\u7406 NULL \u503c<\/strong><\/p>\n<p>\u5982\u679c\u5b57\u7b26\u4e32\u4e3a NULL\uff0cLENGTH() \u51fd\u6570\u5c06\u8fd4\u56de NULL\u3002\u8981\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\uff0c\u53ef\u4ee5\u4f7f\u7528 ISNULL() \u51fd\u6570\u5c06 NULL \u503c\u66ff\u6362\u4e3a\u4e00\u4e2a\u9ed8\u8ba4\u503c\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>LENGTH(ISNULL(string, default_value))<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>SELECT LENGTH(ISNULL(name, 'N\/A')); -- \u66ff\u6362 NULL \u540d\u79f0\u4e3a \"N\/A\"<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>LENGTH() \u51fd\u6570\u662f\u533a\u5206\u5927\u5c0f\u5199\u7684\u3002<\/li>\n<li>LENGTH() \u51fd\u6570\u4e0d\u8003\u8651 Unicode \u5b57\u7b26\u7684\u5bbd\u5b57\u7b26\u8868\u793a\u3002<\/li>\n<li>\u67d0\u4e9b\u6570\u636e\u5e93\u7cfb\u7edf\u53ef\u80fd\u63d0\u4f9b\u5176\u4ed6\u51fd\u6570\u6765\u83b7\u53d6\u5b57\u7b26\u4e32\u957f\u5ea6\uff0c\u4f8b\u5982 DATALENGTH()\u3002\u8bf7\u67e5\u9605\u7279\u5b9a\u6570\u636e\u5e93\u7cfb\u7edf\u7684\u6587\u6863\u4ee5\u83b7\u53d6\u8be6\u7ec6\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fsql\u5b57\u7b26\u4e32\u957f\u5ea6\u600e\u4e48\u770b\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>\u5728 sql \u4e2d\uff0c\u5b57\u7b26\u4e32\u957f\u5ea6\u6307\u5b57\u7b26\u4e32\u4e2d\u5b57\u7b26\u7684\u6570\u91cf\uff08\u4e0d\u542b\u7a7a\u683c\uff09\u3002length() \u51fd\u6570\u53ef\u83b7\u53d6\u5b57\u7b26\u4e32\u957f\u5ea6\uff0c\u8bed\u6cd5\u4e3a length(string)\u3002\u5982\u679c\u5b57\u7b26\u4e32\u4e3a null\uff0c\u4f7f\u7528 isnull() \u51fd\u6570\u66ff\u6362\u4e3a\u9ed8\u8ba4\u503c\uff0c\u5982 length(isnull(name, &#8216;n\/a&#8217;))\u3002\u9700\u8981\u6ce8\u610f length() \u51fd\u6570\u533a\u5206\u5927\u5c0f\u5199\u4e14\u4e0d\u8003\u8651 unicode \u5b57\u7b26\u7684\u5bbd\u5b57\u7b26\u8868\u793a\u3002 SQL \u5b57\u7b26\u4e32\u957f\u5ea6 \u5b57\u7b26\u4e32\u957f\u5ea6\u7684\u5b9a\u4e49 \u5728 SQL \u4e2d\uff0c\u5b57\u7b26\u4e32\u957f\u5ea6\u6307\u7684\u662f\u5b57\u7b26\u4e32\u4e2d\u5b57\u7b26\u7684\u6570\u91cf\uff0c\u4e0d\u5305\u62ec\u7a7a\u683c\u3002 \u83b7\u53d6\u5b57\u7b26\u4e32\u957f\u5ea6 \u83b7\u53d6\u5b57\u7b26\u4e32\u957f\u5ea6\u53ef\u4ee5\u4f7f\u7528 LENGTH() \u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u6536\u4e00\u4e2a\u5b57\u7b26\u4e32\u53c2\u6570\u5e76\u8fd4\u56de\u5176\u957f\u5ea6\u3002 \u8bed\u6cd5\uff1a LENGTH(string) \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b\uff1a SELECT LENGTH(&#8216;Hello World&#8217;); &#8212; \u8fd4\u56de 11 \u767b\u5f55\u540e\u590d\u5236 \u5904\u7406 NULL \u503c \u5982\u679c\u5b57\u7b26\u4e32\u4e3a NULL\uff0cLENGTH() \u51fd\u6570\u5c06\u8fd4\u56de NULL\u3002\u8981\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\uff0c\u53ef\u4ee5\u4f7f\u7528 ISNULL() \u51fd\u6570\u5c06 NULL \u503c\u66ff\u6362\u4e3a\u4e00\u4e2a\u9ed8\u8ba4\u503c\u3002 \u8bed\u6cd5\uff1a LENGTH(ISNULL(string, default_value)) \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b\uff1a SELECT LENGTH(ISNULL(name, &#8216;N\/A&#8217;)); &#8212; [&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-5665","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5665","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=5665"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5665\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5665"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5665"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}