{"id":65405,"date":"2024-10-14T13:44:20","date_gmt":"2024-10-14T05:44:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/65405\/"},"modified":"2024-10-14T13:44:20","modified_gmt":"2024-10-14T05:44:20","slug":"mssql%e6%88%aa%e5%8f%96%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%b8%ad%e7%9a%84%e7%a9%ba%e6%a0%bc%e6%96%b9%e6%b3%95%ef%bc%88mssql%e6%88%aa%e5%8f%96%e7%a9%ba%e6%a0%bc%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/65405\/","title":{"rendered":"MSSQL\u622a\u53d6\u5b57\u7b26\u4e32\u4e2d\u7684\u7a7a\u683c\u65b9\u6cd5\uff08mssql\u622a\u53d6\u7a7a\u683c\uff09"},"content":{"rendered":"<h1 id=\"mssql%e6%88%aa%e5%8f%96%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%b8%ad%e7%9a%84%e7%a9%ba%e6%a0%bc%e6%96%b9%e6%b3%95%ef%bc%88mssql%e6%88%aa%e5%8f%96%e7%a9%ba%e6%a0%bc%ef%bc%89-QEZdxpUsvp\">MSSQL\u622a\u53d6\u5b57\u7b26\u4e32\u4e2d\u7684\u7a7a\u683c\u65b9\u6cd5\uff08mssql\u622a\u53d6\u7a7a\u683c\uff09<\/h1>\n<p>\u5728\u4f7f\u7528Microsoft SQL Server\uff08MSSQL\uff09\u9032\u884c\u6578\u64da\u8655\u7406\u6642\uff0c\u5b57\u7b26\u4e32\u64cd\u4f5c\u662f\u5e38\u898b\u7684\u9700\u6c42\u4e4b\u4e00\u3002\u7279\u5225\u662f\u5728\u8655\u7406\u7528\u6236\u8f38\u5165\u6216\u5f9e\u5916\u90e8\u6578\u64da\u6e90\u5c0e\u5165\u7684\u6578\u64da\u6642\uff0c\u5b57\u7b26\u4e32\u4e2d\u53ef\u80fd\u6703\u5305\u542b\u591a\u9918\u7684\u7a7a\u683c\u3002\u9019\u4e9b\u7a7a\u683c\u4e0d\u50c5\u5f71\u97ff\u6578\u64da\u7684\u6574\u6f54\u6027\uff0c\u9084\u53ef\u80fd\u5c0e\u81f4\u67e5\u8a62\u6027\u80fd\u7684\u4e0b\u964d\u3002\u56e0\u6b64\uff0c\u4e86\u89e3\u5982\u4f55\u5728MSSQL\u4e2d\u622a\u53d6\u5b57\u7b26\u4e32\u4e2d\u7684\u7a7a\u683c\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n<h2 id=\"%e7%a9%ba%e6%a0%bc%e7%9a%84%e9%a1%9e%e5%9e%8b-QEZdxpUsvp\">\u7a7a\u683c\u7684\u985e\u578b<\/h2>\n<p>\u5728MSSQL\u4e2d\uff0c\u7a7a\u683c\u4e3b\u8981\u6709\u5169\u7a2e\u985e\u578b\uff1a<\/p>\n<ul>\n<li>\u524d\u5c0e\u7a7a\u683c\uff1a\u4f4d\u65bc\u5b57\u7b26\u4e32\u958b\u982d\u7684\u7a7a\u683c\u3002<\/li>\n<li>\u5c3e\u96a8\u7a7a\u683c\uff1a\u4f4d\u65bc\u5b57\u7b26\u4e32\u7d50\u5c3e\u7684\u7a7a\u683c\u3002<\/li>\n<\/ul>\n<p>\u6b64\u5916\uff0c\u9084\u6709\u4e2d\u9593\u7684\u7a7a\u683c\uff0c\u9019\u4e9b\u7a7a\u683c\u901a\u5e38\u4e0d\u6703\u5f71\u97ff\u5b57\u7b26\u4e32\u7684\u8655\u7406\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\u4e5f\u9700\u8981\u8003\u616e\u3002<\/p>\n<h2 id=\"%e4%bd%bf%e7%94%a8trim%e5%87%bd%e6%95%b8-QEZdxpUsvp\">\u4f7f\u7528TRIM\u51fd\u6578<\/h2>\n<p>\u5f9eSQL Server 2017\u958b\u59cb\uff0cMSSQL\u5f15\u5165\u4e86TRIM\u51fd\u6578\uff0c\u9019\u662f\u4e00\u500b\u975e\u5e38\u65b9\u4fbf\u7684\u51fd\u6578\uff0c\u7528\u65bc\u53bb\u9664\u5b57\u7b26\u4e32\u5169\u7aef\u7684\u7a7a\u683c\u3002\u5176\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>TRIM ( [ characters ] FROM string )<\/code><\/pre>\n<p>\u5982\u679c\u4e0d\u6307\u5b9a\u5b57\u7b26\uff0c\u5247\u9ed8\u8a8d\u53bb\u9664\u7a7a\u683c\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u793a\u4f8b\uff1a<\/p>\n<pre><code>SELECT TRIM('   Hello World!   ') AS TrimmedString;<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de\uff1a<\/p>\n<pre><code>Hello World!<\/code><\/pre>\n<h2 id=\"%e4%bd%bf%e7%94%a8ltrim%e5%92%8crtrim%e5%87%bd%e6%95%b8-QEZdxpUsvp\">\u4f7f\u7528LTRIM\u548cRTRIM\u51fd\u6578<\/h2>\n<p>\u5728SQL Server 2016\u53ca\u4e4b\u524d\u7684\u7248\u672c\u4e2d\uff0c\u6c92\u6709TRIM\u51fd\u6578\uff0c\u4f46\u53ef\u4ee5\u4f7f\u7528LTRIM\u548cRTRIM\u51fd\u6578\u4f86\u5206\u5225\u53bb\u9664\u524d\u5c0e\u7a7a\u683c\u548c\u5c3e\u96a8\u7a7a\u683c\u3002\u5176\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>LTRIM(string) -- \u53bb\u9664\u524d\u5c0e\u7a7a\u683c\nRTRIM(string) -- \u53bb\u9664\u5c3e\u96a8\u7a7a\u683c<\/code><\/pre>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528\u9019\u5169\u500b\u51fd\u6578\uff1a<\/p>\n<pre><code>SELECT LTRIM(RTRIM('   Hello World!   ')) AS TrimmedString;<\/code><\/pre>\n<p>\u9019\u540c\u6a23\u6703\u8fd4\u56de\uff1a<\/p>\n<pre><code>Hello World!<\/code><\/pre>\n<h2 id=\"%e8%99%95%e7%90%86%e4%b8%ad%e9%96%93%e7%a9%ba%e6%a0%bc-QEZdxpUsvp\">\u8655\u7406\u4e2d\u9593\u7a7a\u683c<\/h2>\n<p>\u5982\u679c\u9700\u8981\u53bb\u9664\u5b57\u7b26\u4e32\u4e2d\u9593\u7684\u591a\u9918\u7a7a\u683c\uff0c\u53ef\u4ee5\u4f7f\u7528REPLACE\u51fd\u6578\u3002\u9019\u500b\u51fd\u6578\u53ef\u4ee5\u5c07\u6307\u5b9a\u7684\u5b57\u7b26\u66ff\u63db\u70ba\u53e6\u4e00\u500b\u5b57\u7b26\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u5c07\u591a\u500b\u7a7a\u683c\u66ff\u63db\u70ba\u55ae\u500b\u7a7a\u683c\uff1a<\/p>\n<pre><code>SELECT REPLACE('Hello    World!', '    ', ' ') AS CleanedString;<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de\uff1a<\/p>\n<pre><code>Hello World!<\/code><\/pre>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u9019\u7a2e\u65b9\u6cd5\u50c5\u9069\u7528\u65bc\u5df2\u77e5\u7684\u7a7a\u683c\u6578\u91cf\u3002\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u6709\u4e0d\u5b9a\u6578\u91cf\u7684\u7a7a\u683c\uff0c\u5247\u53ef\u80fd\u9700\u8981\u4f7f\u7528\u66f4\u8907\u96dc\u7684\u908f\u8f2f\u4f86\u8655\u7406\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-QEZdxpUsvp\">\u7d50\u8ad6<\/h2>\n<p>\u5728MSSQL\u4e2d\uff0c\u8655\u7406\u5b57\u7b26\u4e32\u4e2d\u7684\u7a7a\u683c\u662f\u6578\u64da\u6e05\u7406\u904e\u7a0b\u4e2d\u7684\u4e00\u500b\u91cd\u8981\u6b65\u9a5f\u3002\u901a\u904e\u4f7f\u7528TRIM\u3001LTRIM\u3001RTRIM\u548cREPLACE\u7b49\u51fd\u6578\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u53bb\u9664\u4e0d\u5fc5\u8981\u7684\u7a7a\u683c\uff0c\u5f9e\u800c\u63d0\u9ad8\u6578\u64da\u7684\u6574\u6f54\u6027\u548c\u67e5\u8a62\u6027\u80fd\u3002\u9019\u4e9b\u65b9\u6cd5\u4e0d\u50c5\u9069\u7528\u65bc\u65e5\u5e38\u7684\u6578\u64da\u8655\u7406\uff0c\u9084\u53ef\u4ee5\u5728\u6578\u64da\u9077\u79fb\u548c\u6574\u5408\u904e\u7a0b\u4e2d\u767c\u63ee\u91cd\u8981\u4f5c\u7528\u3002<\/p>\n<p>\u5982\u679c\u60a8\u5c0d\u65bc\u5982\u4f55\u5728MSSQL\u4e2d\u9032\u884c\u66f4\u9ad8\u6548\u7684\u6578\u64da\u8655\u7406\u6709\u8208\u8da3\uff0c\u6216\u8005\u9700\u8981\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684\u6578\u64da\u5eab\u904b\u884c\uff0c\u6b61\u8fce\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3MSSQL\u4e2d\u622a\u53d6\u5b57\u7b26\u4e32\u7a7a\u683c\u7684\u65b9\u6cd5\uff0c\u638c\u63e1\u5982\u4f55\u6709\u6548\u5904\u7406\u548c\u6e05\u7406\u6570\u636e\u4e2d\u7684\u7a7a\u683c\u95ee\u9898\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-65405","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/65405","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=65405"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/65405\/revisions"}],"predecessor-version":[{"id":65406,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/65405\/revisions\/65406"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=65405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=65405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=65405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}