{"id":1737,"date":"2025-02-16T09:09:28","date_gmt":"2025-02-16T01:09:28","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=1737"},"modified":"2025-02-16T09:09:28","modified_gmt":"2025-02-16T01:09:28","slug":"sql-lcase-%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/02\/16\/sql-lcase-%e5%87%bd%e6%95%b0\/","title":{"rendered":"SQL LCASE() \u51fd\u6570"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><code>LCASE()<\/code> \u662f SQL \u4e2d\u7684\u4e00\u4e2a\u51fd\u6570\uff0c\u7528\u4e8e\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u5b57\u6bcd\u8f6c\u6362\u4e3a\u5c0f\u5199\u5b57\u6bcd\u3002\u5b83\u5728\u5927\u591a\u6570\u6570\u636e\u5e93\u7cfb\u7edf\u4e2d\u901a\u5e38\u4e0e <code>LOWER()<\/code> \u51fd\u6570\u7b49\u4ef7\uff0c\u529f\u80fd\u76f8\u540c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong><code>LCASE()<\/code> \u7684\u57fa\u672c\u8bed\u6cd5<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT LCASE(column_name)\nFROM table_name;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>column_name<\/code>\uff1a\u4f60\u5e0c\u671b\u8f6c\u6362\u4e3a\u5c0f\u5199\u5b57\u6bcd\u7684\u5217\u3002<\/li>\n\n\n\n<li><code>table_name<\/code>\uff1a\u5305\u542b\u8981\u64cd\u4f5c\u6570\u636e\u7684\u8868\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong><code>LCASE()<\/code> \u7684\u793a\u4f8b<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u8bbe\u4f60\u6709\u4e00\u4e2a\u540d\u4e3a <code>employees<\/code> \u7684\u8868\uff0c\u5305\u542b\u4ee5\u4e0b\u6570\u636e\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>emp_id<\/th><th>emp_name<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Alice<\/td><\/tr><tr><td>2<\/td><td>Bob<\/td><\/tr><tr><td>3<\/td><td>Charlie<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u5e0c\u671b\u5c06 <code>emp_name<\/code> \u5217\u7684\u6240\u6709\u540d\u5b57\u8f6c\u6362\u4e3a\u5c0f\u5199\u5b57\u6bcd\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT emp_id, LCASE(emp_name) AS emp_name_lowercase\nFROM employees;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u67e5\u8be2\u7ed3\u679c<\/strong>\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>emp_id<\/th><th>emp_name_lowercase<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>alice<\/td><\/tr><tr><td>2<\/td><td>bob<\/td><\/tr><tr><td>3<\/td><td>charlie<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong><code>LCASE()<\/code> \u4e0e <code>LOWER()<\/code> \u51fd\u6570\u7684\u5bf9\u6bd4<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>LCASE()<\/code> \u548c <code>LOWER()<\/code> \u90fd\u662f\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u5b57\u6bcd\u8f6c\u6362\u4e3a\u5c0f\u5199\u7684\u51fd\u6570\u3002\u5b83\u4eec\u5728\u8bb8\u591a\u6570\u636e\u5e93\u7cfb\u7edf\u4e2d\u662f\u7b49\u4ef7\u7684\uff0c\u53ef\u4ee5\u4e92\u6362\u4f7f\u7528\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4e24\u6761\u67e5\u8be2\u8fd4\u56de\u76f8\u540c\u7684\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT LCASE(emp_name) AS emp_name_lowercase\nFROM employees;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u548c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT LOWER(emp_name) AS emp_name_lowercase\nFROM employees;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u5927\u591a\u6570\u6570\u636e\u5e93\u7cfb\u7edf\u4e2d\uff0c<code>LOWER()<\/code> \u662f\u66f4\u5e38\u89c1\u7684\u547d\u540d\u65b9\u5f0f\uff0c\u56e0\u6b64\u4f60\u53ef\u80fd\u66f4\u591a\u5730\u770b\u5230 <code>LOWER()<\/code> \u88ab\u4f7f\u7528\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>\u4f7f\u7528 <code>LCASE()<\/code> \u8fdb\u884c\u6761\u4ef6\u8fc7\u6ee4<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u53ef\u4ee5\u7ed3\u5408 <code>LCASE()<\/code> \u4e0e <code>WHERE<\/code> \u5b50\u53e5\u8fdb\u884c\u5927\u5c0f\u5199\u4e0d\u654f\u611f\u7684\u6761\u4ef6\u8fc7\u6ee4\u3002\u4f8b\u5982\uff0c\u67e5\u627e\u540d\u5b57\u4e3a <code>\"alice\"<\/code> \u7684\u5458\u5de5\uff0c\u65e0\u8bba\u8f93\u5165\u7684\u5927\u5c0f\u5199\u5982\u4f55\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT emp_id, emp_name\nFROM employees\nWHERE LCASE(emp_name) = 'alice';<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u67e5\u8be2\u7ed3\u679c<\/strong>\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>emp_id<\/th><th>emp_name<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Alice<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8fd9\u4e2a\u67e5\u8be2\u4e2d\uff0c<code>LCASE()<\/code> \u5c06 <code>emp_name<\/code> \u5217\u7684\u6240\u6709\u503c\u8f6c\u6362\u4e3a\u5c0f\u5199\u5b57\u6bcd\uff0c\u4ece\u800c\u786e\u4fdd\u67e5\u8be2\u5ffd\u7565\u5927\u5c0f\u5199\uff0c\u627e\u5230\u7b26\u5408\u6761\u4ef6\u7684\u8bb0\u5f55\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. <strong><code>LCASE()<\/code> \u5b50\u67e5\u8be2\u7684\u5e94\u7528<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u8fd8\u53ef\u4ee5\u5728\u5b50\u67e5\u8be2\u4e2d\u4f7f\u7528 <code>LCASE()<\/code> \u8fdb\u884c\u5927\u5c0f\u5199\u8f6c\u6362\u3002\u4f8b\u5982\uff0c\u67e5\u8be2\u6709\u5c0f\u5199\u90e8\u95e8\u540d\u7684\u5458\u5de5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT emp_id, emp_name\nFROM employees\nWHERE LCASE(emp_name) IN (\n    SELECT LCASE(department_name)\n    FROM departments\n    WHERE department_name = 'hr'\n);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6. <strong>\u5e38\u89c1\u95ee\u9898\u53ca\u89e3\u51b3\u65b9\u6848<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">6.1 <strong>\u5728 <code>LCASE()<\/code> \u4e2d\u5ffd\u7565\u975e\u5b57\u6bcd\u5b57\u7b26<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><code>LCASE()<\/code> \u53ea\u4f1a\u8f6c\u6362\u5b57\u6bcd\u5b57\u7b26\uff08A-Z\uff09\uff0c\u5bf9\u4e8e\u975e\u5b57\u6bcd\u5b57\u7b26\uff08\u5982\u6570\u5b57\u3001\u6807\u70b9\u7b26\u53f7\uff09\uff0c\u5b83\u4eec\u4fdd\u6301\u4e0d\u53d8\u3002\u5982\u679c\u4f60\u5e0c\u671b\u5904\u7406\u5305\u542b\u6570\u5b57\u6216\u5176\u4ed6\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\uff0c\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u51fd\u6570\uff08\u5982 <code>REGEXP_REPLACE()<\/code>\uff09\u6765\u9884\u5904\u7406\u5b57\u7b26\u4e32\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">6.2 <strong>\u5927\u5c0f\u5199\u95ee\u9898\u4e0e\u67e5\u8be2\u4e0d\u5339\u914d<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u6709\u65f6\u4f60\u53ef\u80fd\u4f1a\u9047\u5230\u67e5\u8be2\u7ed3\u679c\u4e0d\u5339\u914d\u7684\u95ee\u9898\uff0c\u8fd9\u901a\u5e38\u4e0e\u6570\u636e\u4e2d\u7684\u5927\u5c0f\u5199\u5dee\u5f02\u6709\u5173\u3002<code>LCASE()<\/code> \u53ef\u4ee5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u4f46\u4f60\u4e5f\u53ef\u4ee5\u8003\u8651\u5176\u4ed6\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528 <code>LOWER()<\/code><\/strong>\uff1a<code>LOWER()<\/code> \u51fd\u6570\u7684\u6548\u679c\u4e0e <code>LCASE()<\/code> \u76f8\u540c\uff0c\u5b83\u53ef\u80fd\u662f\u66f4\u6807\u51c6\u7684\u9009\u62e9\u3002<\/li>\n\n\n\n<li><strong><code>COLLATE<\/code> \u5173\u952e\u5b57<\/strong>\uff1a\u5728\u67d0\u4e9b\u6570\u636e\u5e93\u7cfb\u7edf\u4e2d\uff08\u5982 MySQL\uff09\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 <code>COLLATE<\/code> \u6765\u8bbe\u7f6e\u5b57\u7b26\u96c6\u548c\u6392\u5e8f\u89c4\u5219\uff0c\u8fdb\u884c\u5927\u5c0f\u5199\u4e0d\u654f\u611f\u7684\u6bd4\u8f83\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT emp_id, emp_name\nFROM employees\nWHERE emp_name COLLATE utf8_general_ci = 'alice';<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">6.3 <strong><code>LCASE()<\/code> \u4e0e\u6027\u80fd\u95ee\u9898<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528 <code>LCASE()<\/code>\uff08\u6216 <code>LOWER()<\/code>\uff09\u65f6\uff0c\u53ef\u80fd\u4f1a\u5f71\u54cd\u67e5\u8be2\u7684\u6027\u80fd\uff0c\u5c24\u5176\u662f\u5728\u5927\u6570\u636e\u96c6\u4e0a\u8fdb\u884c\u67e5\u8be2\u65f6\u3002\u7531\u4e8e <code>LCASE()<\/code> \u4f1a\u5bf9\u6bcf\u4e2a\u5b57\u7b26\u4e32\u503c\u8fdb\u884c\u8f6c\u6362\uff0c\u5b83\u53ef\u80fd\u589e\u52a0\u6570\u636e\u5e93\u7684\u8ba1\u7b97\u8d1f\u62c5\u3002\u4e3a\u4e86\u4f18\u5316\u6027\u80fd\uff0c\u8003\u8651\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5c3d\u91cf\u907f\u514d\u5728\u67e5\u8be2\u6761\u4ef6\u4e2d\u9891\u7e41\u4f7f\u7528 <code>LCASE()<\/code><\/strong>\uff0c\u5c24\u5176\u662f\u5728\u6d89\u53ca\u5927\u91cf\u6570\u636e\u7684\u60c5\u51b5\u4e0b\u3002<\/li>\n\n\n\n<li><strong>\u4f7f\u7528\u7d22\u5f15<\/strong>\uff1a\u786e\u4fdd\u67e5\u8be2\u7684\u5217\uff08\u5982 <code>emp_name<\/code>\uff09\u5df2\u7ecf\u5efa\u7acb\u4e86\u5408\u9002\u7684\u7d22\u5f15\uff0c\u907f\u514d\u5168\u8868\u626b\u63cf\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">7. <strong>\u603b\u7ed3<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>LCASE()<\/code> \u662f\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u5b57\u6bcd\u8f6c\u6362\u4e3a\u5c0f\u5199\u7684 SQL \u51fd\u6570\uff0c\u901a\u5e38\u4e0e <code>LOWER()<\/code> \u529f\u80fd\u76f8\u540c\u3002<\/li>\n\n\n\n<li>\u53ef\u4ee5\u4f7f\u7528 <code>LCASE()<\/code> \u5728\u67e5\u8be2\u4e2d\u8fdb\u884c\u5927\u5c0f\u5199\u4e0d\u654f\u611f\u7684\u6bd4\u8f83\uff0c\u6216\u8005\u5c06\u5217\u6570\u636e\u8f6c\u6362\u4e3a\u5c0f\u5199\u3002<\/li>\n\n\n\n<li><code>LCASE()<\/code> \u53ea\u5f71\u54cd\u5b57\u6bcd\u5b57\u7b26\uff0c\u5bf9\u4e8e\u6570\u5b57\u548c\u5176\u4ed6\u5b57\u7b26\u65e0\u6548\u3002<\/li>\n\n\n\n<li>\u5728\u4f7f\u7528 <code>LCASE()<\/code> \u5904\u7406\u5927\u6570\u636e\u65f6\uff0c\u5e94\u8003\u8651\u6027\u80fd\u4f18\u5316\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>LCASE() \u662f SQL \u4e2d\u7684\u4e00\u4e2a\u51fd\u6570\uff0c\u7528\u4e8e\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u5b57\u6bcd\u8f6c\u6362\u4e3a\u5c0f\u5199\u5b57\u6bcd\u3002\u5b83\u5728\u5927\u591a\u6570\u6570\u636e\u5e93\u7cfb\u7edf\u4e2d\u901a\u5e38\u4e0e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-1737","post","type-post","status-publish","format-standard","hentry","category-sql"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1737","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=1737"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1737\/revisions"}],"predecessor-version":[{"id":1738,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/1737\/revisions\/1738"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=1737"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=1737"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=1737"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}