{"id":80894,"date":"2024-10-16T14:49:16","date_gmt":"2024-10-16T06:49:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/80894\/"},"modified":"2024-10-16T14:49:16","modified_gmt":"2024-10-16T06:49:16","slug":"mysql%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%b8%ad%e7%9a%84%e5%a4%a7%e5%b0%8f%e5%af%ab%e8%bd%89%e6%8f%9b%e8%a9%b3%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/80894\/","title":{"rendered":"MySQL\u5b57\u7b26\u4e32\u4e2d\u7684\u5927\u5c0f\u5beb\u8f49\u63db\u8a73\u89e3"},"content":{"rendered":"<h1 id=\"mysql%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%b8%ad%e7%9a%84%e5%a4%a7%e5%b0%8f%e5%af%ab%e8%bd%89%e6%8f%9b%e8%a9%b3%e8%a7%a3-ieAcQanjHa\">MySQL\u5b57\u7b26\u4e32\u4e2d\u7684\u5927\u5c0f\u5beb\u8f49\u63db\u8a73\u89e3<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u4e2d\uff0c\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\u5beb\u8f49\u63db\u662f\u4e00\u500b\u5e38\u898b\u7684\u9700\u6c42\u3002MySQL\u4f5c\u70ba\u4e00\u500b\u6d41\u884c\u7684\u95dc\u4fc2\u578b\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u63d0\u4f9b\u4e86\u591a\u7a2e\u65b9\u6cd5\u4f86\u8655\u7406\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\u5beb\u8f49\u63db\u3002\u672c\u6587\u5c07\u8a73\u7d30\u4ecb\u7d39MySQL\u4e2d\u5b57\u7b26\u4e32\u5927\u5c0f\u5beb\u8f49\u63db\u7684\u76f8\u95dc\u51fd\u6578\u53ca\u5176\u4f7f\u7528\u65b9\u6cd5\u3002<\/p>\n<h2 id=\"1-mysql%e4%b8%ad%e7%9a%84%e5%a4%a7%e5%b0%8f%e5%af%ab%e8%bd%89%e6%8f%9b%e5%87%bd%e6%95%b8-ieAcQanjHa\">1. MySQL\u4e2d\u7684\u5927\u5c0f\u5beb\u8f49\u63db\u51fd\u6578<\/h2>\n<p>MySQL\u63d0\u4f9b\u4e86\u4e09\u500b\u4e3b\u8981\u7684\u51fd\u6578\u4f86\u9032\u884c\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\u5beb\u8f49\u63db\uff1a<\/p>\n<ul>\n<li><code>UPPER()<\/code>\uff1a\u5c07\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u5b57\u6bcd\u8f49\u63db\u70ba\u5927\u5beb\u3002<\/li>\n<li><code>LOWER()<\/code>\uff1a\u5c07\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u5b57\u6bcd\u8f49\u63db\u70ba\u5c0f\u5beb\u3002<\/li>\n<li><code>INITCAP()<\/code>\uff1a\u5c07\u5b57\u7b26\u4e32\u4e2d\u7684\u6bcf\u500b\u55ae\u8a5e\u7684\u9996\u5b57\u6bcd\u8f49\u63db\u70ba\u5927\u5beb\uff0c\u5176\u9918\u5b57\u6bcd\u8f49\u63db\u70ba\u5c0f\u5beb\u3002<\/li>\n<\/ul>\n<h2 id=\"2-%e4%bd%bf%e7%94%a8%e7%a4%ba%e4%be%8b-ieAcQanjHa\">2. \u4f7f\u7528\u793a\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u9019\u4e9b\u51fd\u6578\u7684\u4f7f\u7528\u793a\u4f8b\uff1a<\/p>\n<pre><code>SELECT UPPER('hello world');  -- \u7d50\u679c\uff1a'HELLO WORLD'\nSELECT LOWER('HELLO WORLD');  -- \u7d50\u679c\uff1a'hello world'\nSELECT INITCAP('hello world'); -- \u7d50\u679c\uff1a'Hello World'\n<\/code><\/pre>\n<h3 id=\"2-1-upper-%e5%87%bd%e6%95%b8-ieAcQanjHa\">2.1 UPPER() \u51fd\u6578<\/h3>\n<p><code>UPPER()<\/code>\u51fd\u6578\u5c07\u6240\u6709\u5b57\u6bcd\u8f49\u63db\u70ba\u5927\u5beb\uff0c\u9019\u5728\u9700\u8981\u7d71\u4e00\u683c\u5f0f\u6642\u975e\u5e38\u6709\u7528\u3002\u4f8b\u5982\uff0c\u5728\u9032\u884c\u7528\u6236\u540d\u6216\u96fb\u5b50\u90f5\u4ef6\u5730\u5740\u7684\u6bd4\u8f03\u6642\uff0c\u5c07\u6240\u6709\u5b57\u6bcd\u8f49\u63db\u70ba\u5927\u5beb\u53ef\u4ee5\u907f\u514d\u56e0\u5927\u5c0f\u5beb\u4e0d\u540c\u800c\u5c0e\u81f4\u7684\u932f\u8aa4\u3002<\/p>\n<pre><code>SELECT UPPER(username) FROM users;\n<\/code><\/pre>\n<h3 id=\"2-2-lower-%e5%87%bd%e6%95%b8-ieAcQanjHa\">2.2 LOWER() \u51fd\u6578<\/h3>\n<p>&lt;p<code>LOWER()<\/code>\u51fd\u6578\u5247\u5c07\u6240\u6709\u5b57\u6bcd\u8f49\u63db\u70ba\u5c0f\u5beb\uff0c\u9019\u5728\u8655\u7406\u4e0d\u5340\u5206\u5927\u5c0f\u5beb\u7684\u67e5\u8a62\u6642\u7279\u5225\u6709\u7528\u3002\u4f8b\u5982\uff0c\u7576\u7528\u6236\u8f38\u5165\u7684\u67e5\u8a62\u53ef\u80fd\u5305\u542b\u4e0d\u540c\u7684\u5927\u5c0f\u5beb\u6642\uff0c\u4f7f\u7528<code>LOWER()<\/code>\u53ef\u4ee5\u78ba\u4fdd\u67e5\u8a62\u7684\u6e96\u78ba\u6027\u3002<\/p>\n<pre><code>SELECT * FROM users WHERE LOWER(email) = LOWER('Example@Domain.com');\n<\/code><\/pre>\n<h3 id=\"2-3-initcap-%e5%87%bd%e6%95%b8-ieAcQanjHa\">2.3 INITCAP() \u51fd\u6578<\/h3>\n<p><code>INITCAP()<\/code>\u51fd\u6578\u5728\u8655\u7406\u6a19\u984c\u6216\u540d\u7a31\u6642\u975e\u5e38\u6709\u7528\uff0c\u56e0\u70ba\u5b83\u53ef\u4ee5\u81ea\u52d5\u5c07\u6bcf\u500b\u55ae\u8a5e\u7684\u9996\u5b57\u6bcd\u8f49\u63db\u70ba\u5927\u5beb\u3002\u9019\u5728\u751f\u6210\u5831\u544a\u6216\u986f\u793a\u7528\u6236\u540d\u7a31\u6642\u7279\u5225\u65b9\u4fbf\u3002<\/p>\n<pre><code>SELECT INITCAP(first_name) FROM employees;\n<\/code><\/pre>\n<h2 id=\"3-%e5%a4%a7%e5%b0%8f%e5%af%ab%e8%bd%89%e6%8f%9b%e7%9a%84%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-ieAcQanjHa\">3. \u5927\u5c0f\u5beb\u8f49\u63db\u7684\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u4f7f\u7528\u5927\u5c0f\u5beb\u8f49\u63db\u51fd\u6578\u6642\uff0c\u6709\u5e7e\u9ede\u9700\u8981\u6ce8\u610f\uff1a<\/p>\n<ul>\n<li>\u5b57\u7b26\u96c6\uff1a\u4e0d\u540c\u7684\u5b57\u7b26\u96c6\u53ef\u80fd\u6703\u5f71\u97ff\u5927\u5c0f\u5beb\u8f49\u63db\u7684\u7d50\u679c\uff0c\u7279\u5225\u662f\u5728\u8655\u7406\u975e\u82f1\u6587\u5b57\u6bcd\u6642\u3002<\/li>\n<li>\u6027\u80fd\uff1a\u5728\u5927\u578b\u6578\u64da\u96c6\u4e0a\u4f7f\u7528\u9019\u4e9b\u51fd\u6578\u53ef\u80fd\u6703\u5f71\u97ff\u67e5\u8a62\u6027\u80fd\uff0c\u56e0\u6b64\u5728\u8a2d\u8a08\u6578\u64da\u5eab\u6642\u61c9\u8003\u616e\u5230\u9019\u4e00\u9ede\u3002<\/li>\n<li>\u4e0d\u5340\u5206\u5927\u5c0f\u5beb\u7684\u6bd4\u8f03\uff1a\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u4f7f\u7528<code>COLLATE<\/code>\u5b50\u53e5\u53ef\u4ee5\u66f4\u6709\u6548\u5730\u9032\u884c\u4e0d\u5340\u5206\u5927\u5c0f\u5beb\u7684\u6bd4\u8f03\u3002<\/li>\n<\/ul>\n<h2 id=\"4-%e7%b5%90%e8%ab%96-ieAcQanjHa\">4. \u7d50\u8ad6<\/h2>\n<p>MySQL\u63d0\u4f9b\u7684\u5b57\u7b26\u4e32\u5927\u5c0f\u5beb\u8f49\u63db\u51fd\u6578\u4f7f\u5f97\u5728\u6578\u64da\u5eab\u64cd\u4f5c\u4e2d\u8655\u7406\u5b57\u7b26\u4e32\u8b8a\u5f97\u66f4\u52a0\u9748\u6d3b\u548c\u65b9\u4fbf\u3002\u7121\u8ad6\u662f\u9032\u884c\u6578\u64da\u6e05\u7406\u3001\u67e5\u8a62\u9084\u662f\u5831\u544a\u751f\u6210\uff0c\u9019\u4e9b\u51fd\u6578\u90fd\u80fd\u5920\u5e6b\u52a9\u958b\u767c\u8005\u63d0\u9ad8\u6548\u7387\u3002\u4e86\u89e3\u9019\u4e9b\u51fd\u6578\u7684\u4f7f\u7528\u65b9\u6cd5\u53ca\u5176\u6ce8\u610f\u4e8b\u9805\uff0c\u5c07\u6709\u52a9\u65bc\u66f4\u597d\u5730\u7ba1\u7406\u548c\u64cd\u4f5c\u6578\u64da\u3002<\/p>\n<p>\u5982\u9700\u9032\u4e00\u6b65\u4e86\u89e3\u5982\u4f55\u5728\u60a8\u7684\u9805\u76ee\u4e2d\u4f7f\u7528MySQL\uff0c\u6216\u5c0b\u627e\u5408\u9069\u7684<code><a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a><\/code>\u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6df1\u5165\u63a2\u8a0eMySQL\u4e2d\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\u5beb\u8f49\u63db\uff0c\u5305\u62ec\u51fd\u6578\u7528\u6cd5\u3001\u793a\u4f8b\u53ca\u6700\u4f73\u5be6\u8e10\uff0c\u52a9\u4f60\u8f15\u9b06\u638c\u63e1\u6578\u64da\u8655\u7406\u6280\u5de7\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-80894","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/80894","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=80894"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/80894\/revisions"}],"predecessor-version":[{"id":80895,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/80894\/revisions\/80895"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=80894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=80894"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=80894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}