{"id":168535,"date":"2024-11-06T13:11:18","date_gmt":"2024-11-06T05:11:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/168535\/"},"modified":"2024-11-06T13:11:19","modified_gmt":"2024-11-06T05:11:19","slug":"sql-%e4%b8%ad%e7%9a%84%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%93%8d%e4%bd%9c%e5%87%bd%e6%95%b8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/168535\/","title":{"rendered":"SQL \u4e2d\u7684\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6578"},"content":{"rendered":"<h1 id=\"sql-%e4%b8%ad%e7%9a%84%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%93%8d%e4%bd%9c%e5%87%bd%e6%95%b8-PCXNgFyfRo\">SQL \u4e2d\u7684\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6578<\/h1>\n<p>\u5728\u8cc7\u6599\u5eab\u7ba1\u7406\u7cfb\u7d71\u4e2d\uff0c\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6578\u662f\u975e\u5e38\u91cd\u8981\u7684\u5de5\u5177\uff0c\u56e0\u70ba\u5b83\u5011\u80fd\u5920\u5e6b\u52a9\u958b\u767c\u8005\u548c\u6578\u64da\u5206\u6790\u5e2b\u6709\u6548\u5730\u8655\u7406\u548c\u64cd\u4f5c\u6587\u672c\u6578\u64da\u3002SQL\uff08\u7d50\u69cb\u5316\u67e5\u8a62\u8a9e\u8a00\uff09\u63d0\u4f9b\u4e86\u591a\u7a2e\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6578\uff0c\u9019\u4e9b\u51fd\u6578\u53ef\u4ee5\u7528\u4f86\u9032\u884c\u5b57\u7b26\u4e32\u7684\u67e5\u8a62\u3001\u4fee\u6539\u548c\u683c\u5f0f\u5316\u7b49\u64cd\u4f5c\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u4e00\u4e9b\u5e38\u7528\u7684 SQL \u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6578\u53ca\u5176\u61c9\u7528\u793a\u4f8b\u3002<\/p>\n<h2 id=\"1-%e5%ad%97%e7%ac%a6%e4%b8%b2%e9%95%b7%e5%ba%a6%e5%87%bd%e6%95%b8%ef%bc%9alength-PCXNgFyfRo\">1. \u5b57\u7b26\u4e32\u9577\u5ea6\u51fd\u6578\uff1aLENGTH()<\/h2>\n<p>LENGTH() \u51fd\u6578\u7528\u65bc\u8fd4\u56de\u5b57\u7b26\u4e32\u7684\u9577\u5ea6\uff08\u4ee5\u5b57\u7b26\u6578\u8a08\u7b97\uff09\u3002\u9019\u5728\u9700\u8981\u9a57\u8b49\u5b57\u7b26\u4e32\u9577\u5ea6\u6216\u9032\u884c\u6578\u64da\u6e05\u7406\u6642\u975e\u5e38\u6709\u7528\u3002<\/p>\n<pre><code>SELECT LENGTH('Hello, World!') AS StringLength;<\/code><\/pre>\n<p>\u4e0a\u8ff0\u67e5\u8a62\u5c07\u8fd4\u56de\u5b57\u7b26\u4e32 &#8220;Hello, World!&#8221; \u7684\u9577\u5ea6\uff0c\u5373 13\u3002<\/p>\n<h2 id=\"2-%e5%ad%97%e7%ac%a6%e4%b8%b2%e9%80%a3%e6%8e%a5%e5%87%bd%e6%95%b8%ef%bc%9aconcat-PCXNgFyfRo\">2. \u5b57\u7b26\u4e32\u9023\u63a5\u51fd\u6578\uff1aCONCAT()<\/h2>\n<p>CONCAT() \u51fd\u6578\u7528\u65bc\u5c07\u5169\u500b\u6216\u591a\u500b\u5b57\u7b26\u4e32\u9023\u63a5\u5728\u4e00\u8d77\u3002\u9019\u5728\u751f\u6210\u5b8c\u6574\u7684\u6587\u672c\u4fe1\u606f\u6642\u975e\u5e38\u6709\u7528\u3002<\/p>\n<pre><code>SELECT CONCAT('Hello', ', ', 'World!') AS Greeting;<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de &#8220;Hello, World!&#8221;\u3002<\/p>\n<h2 id=\"3-%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%88%aa%e5%8f%96%e5%87%bd%e6%95%b8%ef%bc%9asubstring-PCXNgFyfRo\">3. \u5b57\u7b26\u4e32\u622a\u53d6\u51fd\u6578\uff1aSUBSTRING()<\/h2>\n<p>SUBSTRING() \u51fd\u6578\u7528\u65bc\u5f9e\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u5b50\u5b57\u7b26\u4e32\u3002\u9019\u5728\u9700\u8981\u5f9e\u9577\u5b57\u7b26\u4e32\u4e2d\u7372\u53d6\u7279\u5b9a\u90e8\u5206\u6642\u975e\u5e38\u6709\u7528\u3002<\/p>\n<pre><code>SELECT SUBSTRING('Hello, World!', 1, 5) AS SubString;<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de &#8220;Hello&#8221;\u3002<\/p>\n<h2 id=\"4-%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%9f%a5%e6%89%be%e5%87%bd%e6%95%b8%ef%bc%9ainstr-PCXNgFyfRo\">4. \u5b57\u7b26\u4e32\u67e5\u627e\u51fd\u6578\uff1aINSTR()<\/h2>\n<p>INSTR() \u51fd\u6578\u7528\u65bc\u67e5\u627e\u5b50\u5b57\u7b26\u4e32\u5728\u5b57\u7b26\u4e32\u4e2d\u9996\u6b21\u51fa\u73fe\u7684\u4f4d\u7f6e\u3002\u9019\u5c0d\u65bc\u6aa2\u67e5\u7279\u5b9a\u5b57\u7b26\u6216\u5b57\u7b26\u4e32\u662f\u5426\u5b58\u5728\u65bc\u53e6\u4e00\u500b\u5b57\u7b26\u4e32\u4e2d\u975e\u5e38\u6709\u7528\u3002<\/p>\n<pre><code>SELECT INSTR('Hello, World!', 'World') AS Position;<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de 8\uff0c\u56e0\u70ba &#8220;World&#8221; \u5728\u5b57\u7b26\u4e32\u4e2d\u7684\u8d77\u59cb\u4f4d\u7f6e\u662f\u7b2c 8 \u500b\u5b57\u7b26\u3002<\/p>\n<h2 id=\"5-%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%9b%bf%e6%8f%9b%e5%87%bd%e6%95%b8%ef%bc%9areplace-PCXNgFyfRo\">5. \u5b57\u7b26\u4e32\u66ff\u63db\u51fd\u6578\uff1aREPLACE()<\/h2>\n<p>REPLACE() \u51fd\u6578\u7528\u65bc\u66ff\u63db\u5b57\u7b26\u4e32\u4e2d\u7684\u67d0\u4e9b\u5b57\u7b26\u6216\u5b50\u5b57\u7b26\u4e32\u3002\u9019\u5728\u6578\u64da\u6e05\u7406\u548c\u683c\u5f0f\u5316\u6642\u975e\u5e38\u6709\u7528\u3002<\/p>\n<pre><code>SELECT REPLACE('Hello, World!', 'World', 'SQL') AS NewString;<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de &#8220;Hello, SQL!&#8221;\u3002<\/p>\n<h2 id=\"6-%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%a4%a7%e5%b0%8f%e5%af%ab%e8%bd%89%e6%8f%9b%e5%87%bd%e6%95%b8%ef%bc%9aupper-%e5%92%8c-lower-PCXNgFyfRo\">6. \u5b57\u7b26\u4e32\u5927\u5c0f\u5beb\u8f49\u63db\u51fd\u6578\uff1aUPPER() \u548c LOWER()<\/h2>\n<p>UPPER() \u548c LOWER() \u51fd\u6578\u5206\u5225\u7528\u65bc\u5c07\u5b57\u7b26\u4e32\u8f49\u63db\u70ba\u5927\u5beb\u548c\u5c0f\u5beb\u3002\u9019\u5728\u9700\u8981\u7d71\u4e00\u5b57\u7b26\u4e32\u683c\u5f0f\u6642\u975e\u5e38\u6709\u7528\u3002<\/p>\n<pre><code>SELECT UPPER('Hello, World!') AS UpperCase, LOWER('Hello, World!') AS LowerCase;<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de &#8220;HELLO, WORLD!&#8221; \u548c &#8220;hello, world!&#8221;\u3002<\/p>\n<h2 id=\"7-%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%bf%ae%e5%89%aa%e5%87%bd%e6%95%b8%ef%bc%9atrim-PCXNgFyfRo\">7. \u5b57\u7b26\u4e32\u4fee\u526a\u51fd\u6578\uff1aTRIM()<\/h2>\n<p>TRIM() \u51fd\u6578\u7528\u65bc\u53bb\u9664\u5b57\u7b26\u4e32\u958b\u982d\u548c\u7d50\u5c3e\u7684\u7a7a\u683c\u3002\u9019\u5728\u8655\u7406\u7528\u6236\u8f38\u5165\u6642\u7279\u5225\u91cd\u8981\uff0c\u4ee5\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u7a7a\u683c\u5f71\u97ff\u6578\u64da\u7684\u6e96\u78ba\u6027\u3002<\/p>\n<pre><code>SELECT TRIM('   Hello, World!   ') AS TrimmedString;<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de &#8220;Hello, World!&#8221;\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-PCXNgFyfRo\">\u7e3d\u7d50<\/h2>\n<p>SQL \u4e2d\u7684\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6578\u70ba\u6578\u64da\u8655\u7406\u63d0\u4f9b\u4e86\u5f37\u5927\u7684\u5de5\u5177\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u548c\u6578\u64da\u5206\u6790\u5e2b\u6709\u6548\u5730\u7ba1\u7406\u548c\u64cd\u4f5c\u6587\u672c\u6578\u64da\u3002\u7121\u8ad6\u662f\u8a08\u7b97\u5b57\u7b26\u4e32\u9577\u5ea6\u3001\u9023\u63a5\u5b57\u7b26\u4e32\uff0c\u9084\u662f\u67e5\u627e\u548c\u66ff\u63db\u7279\u5b9a\u5b57\u7b26\uff0c\u9019\u4e9b\u51fd\u6578\u90fd\u80fd\u5920\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u6578\u64da\u8655\u7406\u7684\u4f01\u696d\u4f86\u8aaa\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u53ef\u4ee5\u9032\u4e00\u6b65\u63d0\u5347\u6578\u64da\u5eab\u6027\u80fd\uff0c\u78ba\u4fdd\u696d\u52d9\u904b\u884c\u7684\u7a69\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22 SQL \u4e2d\u7684\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6570\uff0c\u4e86\u89e3\u5982\u4f55\u5904\u7406\u3001\u4fee\u6539\u548c\u5206\u6790\u6587\u672c\u6570\u636e\uff0c\u4ee5\u63d0\u5347\u6570\u636e\u5e93\u67e5\u8be2\u7684\u6548\u7387\u548c\u7075\u6d3b\u6027\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-168535","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/168535","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=168535"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/168535\/revisions"}],"predecessor-version":[{"id":168536,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/168535\/revisions\/168536"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=168535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=168535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=168535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}