{"id":5980,"date":"2024-11-14T10:05:11","date_gmt":"2024-11-14T02:05:11","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5980\/"},"modified":"2024-11-14T10:05:11","modified_gmt":"2024-11-14T02:05:11","slug":"sql%e9%80%9a%e9%85%8d%e7%ac%a6%e4%bb%80%e4%b9%88%e6%84%8f%e6%80%9d","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5980\/","title":{"rendered":"sql\u901a\u914d\u7b26\u4ec0\u4e48\u610f\u601d"},"content":{"rendered":"<blockquote><p>\n  sql \u901a\u914d\u7b26\u5141\u8bb8\u4f60\u4f7f\u7528\u7279\u6b8a\u5b57\u7b26 (%)\u3001(_)\u3001([]) \u548c ([^]) \u5728 select \u8bed\u53e5\u4e2d\u5339\u914d\u5e7f\u6cdb\u7684\u503c\uff0c\u4ece\u800c\u7f16\u5199\u66f4\u901a\u7528\u7684\u67e5\u8be2\u3002\u5b83\u4eec\u5206\u522b\u7528\u4e8e\u5339\u914d\u4efb\u610f\u5b57\u7b26\u3001\u5355\u4e2a\u5b57\u7b26\u3001\u65b9\u62ec\u53f7\u5185\u7684\u5b57\u7b26\u5e8f\u5217\u548c\u65b9\u62ec\u53f7\u5916\u6307\u5b9a\u7684\u5b57\u7b26\u5e8f\u5217\u3002\u8bf7\u8c28\u614e\u4f7f\u7528\u901a\u914d\u7b26\uff0c\u56e0\u4e3a\u4e0d\u540c dbms \u89c4\u5b9a\u4e0d\u540c\uff0c\u6ee5\u7528\u53ef\u80fd\u5bfc\u81f4\u67e5\u8be2\u6027\u80fd\u95ee\u9898\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/12\/2024061203512390441.jpg\" class=\"aligncenter\" title=\"sql\u901a\u914d\u7b26\u4ec0\u4e48\u610f\u601d\u63d2\u56fe\" alt=\"sql\u901a\u914d\u7b26\u4ec0\u4e48\u610f\u601d\u63d2\u56fe\" \/><\/p>\n<p><strong>SQL \u901a\u914d\u7b26<\/strong><\/p>\n<p>SQL \u901a\u914d\u7b26\u662f\u7279\u6b8a\u5b57\u7b26\uff0c\u5141\u8bb8\u4f60\u5728 WHERE \u5b50\u53e5\u4e2d\u5339\u914d\u4e00\u7cfb\u5217\u503c\u3002\u901a\u8fc7\u4f7f\u7528\u901a\u914d\u7b26\uff0c\u4f60\u53ef\u4ee5\u7f16\u5199\u66f4\u7075\u6d3b\u548c\u901a\u7528\u7684\u67e5\u8be2\u3002<\/p>\n<p><strong>\u5e38\u7528\u7684 SQL \u901a\u914d\u7b26<\/strong><\/p>\n<ul>\n<li>\n<p><strong>%<\/strong>\uff1a\u5339\u914d\u4efb\u4f55\u6570\u91cf\u7684\u5b57\u7b26\u3002<\/p>\n<ul>\n<li>\u4f8b\u5982\uff1aSELECT * FROM table WHERE name LIKE &#8216;%John%&#8217;; \u5c06\u5339\u914d\u6240\u6709\u5305\u542b &#8220;John&#8221; \u5b57\u7b26\u4e32\u7684\u540d\u79f0\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>_<\/strong>\uff1a\u5339\u914d\u5355\u4e2a\u5b57\u7b26\u3002<\/p>\n<ul>\n<li>\u4f8b\u5982\uff1aSELECT * FROM table WHERE name LIKE &#8216;_ohn&#8217;; \u5c06\u5339\u914d\u4ee5 &#8220;John&#8221; \u5f00\u5934\u7684\u6240\u6709\u540d\u79f0\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>[]<\/strong>\uff1a\u5339\u914d\u65b9\u62ec\u53f7\u5185\u6307\u5b9a\u7684\u5b57\u7b26\u5e8f\u5217\u3002<\/p>\n<ul>\n<li>\u4f8b\u5982\uff1aSELECT * FROM table WHERE name LIKE &#8216;[Jj][Oo][Hh][Nn]&#8217;; \u5c06\u5339\u914d\u6240\u6709\u4ee5 &#8220;John&#8221; \u6216 &#8220;john&#8221; \u7ed3\u5c3e\u7684\u540d\u79f0\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>[^]<\/strong>\uff1a\u5339\u914d\u65b9\u62ec\u53f7\u5185\u672a\u6307\u5b9a\u7684\u5b57\u7b26\u5e8f\u5217\u3002<\/p>\n<ul>\n<li>\u4f8b\u5982\uff1aSELECT * FROM table WHERE name LIKE &#8216;[^a]ohn&#8217;; \u5c06\u5339\u914d\u6240\u6709\u4e0d\u4ee5 &#8220;a&#8221; \u5f00\u5934\u7684\u4ee5 &#8220;John&#8221; \u7ed3\u5c3e\u7684\u540d\u79f0\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u4f7f\u7528\u901a\u914d\u7b26\u7684\u793a\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u4f7f\u7528\u901a\u914d\u7b26\u7684 SQL \u67e5\u8be2\u793a\u4f8b\uff1a<\/p>\n<ul>\n<li>\u67e5\u627e\u6240\u6709\u4ee5 &#8220;A&#8221; \u5f00\u5934\u7684\u540d\u79f0\uff1aSELECT * FROM table WHERE name LIKE &#8216;A%&#8217;;<\/li>\n<li>\u67e5\u627e\u6240\u6709\u5305\u542b &#8220;er&#8221; \u5b57\u7b26\u4e32\u7684\u540d\u79f0\uff1aSELECT * FROM table WHERE name LIKE &#8216;%er%&#8217;;<\/li>\n<li>\u67e5\u627e\u6240\u6709\u540d\u79f0\u6070\u597d\u4e3a &#8220;John&#8221;\uff1aSELECT * FROM table WHERE name LIKE &#8216;_ohn&#8217;;<\/li>\n<li>\u67e5\u627e\u6240\u6709\u4e0d\u4ee5 &#8220;a&#8221; \u5f00\u5934\u7684\u540d\u79f0\uff1aSELECT * FROM table WHERE name LIKE &#8216;[^a]%&#8217;;<\/li>\n<\/ul>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u901a\u914d\u7b26\u7684\u4f7f\u7528\u56e0\u4e0d\u540c\u7684\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf (DBMS) \u800c\u5f02\u3002<\/li>\n<li>\u6ee5\u7528\u901a\u914d\u7b26\u53ef\u80fd\u4f1a\u5bfc\u81f4\u67e5\u8be2\u6027\u80fd\u4f4e\u4e0b\u3002<\/li>\n<li>\u5728\u4f7f\u7528\u901a\u914d\u7b26\u65f6\uff0c\u52a1\u5fc5\u5c0f\u5fc3\uff0c\u4ee5\u907f\u514d\u610f\u5916\u5339\u914d\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fsql\u901a\u914d\u7b26\u4ec0\u4e48\u610f\u601d\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>sql \u901a\u914d\u7b26\u5141\u8bb8\u4f60\u4f7f\u7528\u7279\u6b8a\u5b57\u7b26 (%)\u3001(_)\u3001([]) \u548c ([^]) \u5728 select \u8bed\u53e5\u4e2d\u5339\u914d\u5e7f\u6cdb\u7684\u503c\uff0c\u4ece\u800c\u7f16\u5199\u66f4\u901a\u7528\u7684\u67e5\u8be2\u3002\u5b83\u4eec\u5206\u522b\u7528\u4e8e\u5339\u914d\u4efb\u610f\u5b57\u7b26\u3001\u5355\u4e2a\u5b57\u7b26\u3001\u65b9\u62ec\u53f7\u5185\u7684\u5b57\u7b26\u5e8f\u5217\u548c\u65b9\u62ec\u53f7\u5916\u6307\u5b9a\u7684\u5b57\u7b26\u5e8f\u5217\u3002\u8bf7\u8c28\u614e\u4f7f\u7528\u901a\u914d\u7b26\uff0c\u56e0\u4e3a\u4e0d\u540c dbms \u89c4\u5b9a\u4e0d\u540c\uff0c\u6ee5\u7528\u53ef\u80fd\u5bfc\u81f4\u67e5\u8be2\u6027\u80fd\u95ee\u9898\u3002 SQL \u901a\u914d\u7b26 SQL \u901a\u914d\u7b26\u662f\u7279\u6b8a\u5b57\u7b26\uff0c\u5141\u8bb8\u4f60\u5728 WHERE \u5b50\u53e5\u4e2d\u5339\u914d\u4e00\u7cfb\u5217\u503c\u3002\u901a\u8fc7\u4f7f\u7528\u901a\u914d\u7b26\uff0c\u4f60\u53ef\u4ee5\u7f16\u5199\u66f4\u7075\u6d3b\u548c\u901a\u7528\u7684\u67e5\u8be2\u3002 \u5e38\u7528\u7684 SQL \u901a\u914d\u7b26 %\uff1a\u5339\u914d\u4efb\u4f55\u6570\u91cf\u7684\u5b57\u7b26\u3002 \u4f8b\u5982\uff1aSELECT * FROM table WHERE name LIKE &#8216;%John%&#8217;; \u5c06\u5339\u914d\u6240\u6709\u5305\u542b &#8220;John&#8221; \u5b57\u7b26\u4e32\u7684\u540d\u79f0\u3002 _\uff1a\u5339\u914d\u5355\u4e2a\u5b57\u7b26\u3002 \u4f8b\u5982\uff1aSELECT * FROM table WHERE name LIKE &#8216;_ohn&#8217;; \u5c06\u5339\u914d\u4ee5 &#8220;John&#8221; \u5f00\u5934\u7684\u6240\u6709\u540d\u79f0\u3002 []\uff1a\u5339\u914d\u65b9\u62ec\u53f7\u5185\u6307\u5b9a\u7684\u5b57\u7b26\u5e8f\u5217\u3002 \u4f8b\u5982\uff1aSELECT * FROM table WHERE name LIKE &#8216;[Jj][Oo][Hh][Nn]&#8217;; \u5c06\u5339\u914d\u6240\u6709\u4ee5 &#8220;John&#8221; \u6216 [&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-5980","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5980","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=5980"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5980\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5980"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5980"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5980"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}