{"id":233,"date":"2023-02-24T05:53:49","date_gmt":"2023-02-23T21:53:49","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=233"},"modified":"2023-04-30T15:21:43","modified_gmt":"2023-04-30T07:21:43","slug":"mysql-like-clause","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/24\/mysql-like-clause\/","title":{"rendered":"MySQL LIKE \u5b50\u53e5"},"content":{"rendered":"<p>\u5f53\u9700\u8981\u9700\u8981\u5339\u914d\u5b57\u6bb5\u7684\u6240\u6709\u8bb0\u5f55\uff0c\u9700\u8981\u5728<code>WHERE<\/code>\u6761\u4ef6\u4e2d\u4f7f\u7528<code>SQL LIKE<\/code>\u5b50\u53e5<\/p>\n<p><code>SQL LIKE<\/code>\u5b50\u53e5\u4e2d\u4f7f\u7528\u767e\u5206\u53f7<code>%<\/code>\u5b57\u7b26\u6765\u8868\u793a\u4efb\u610f\u5b57\u7b26\uff0c\u7c7b\u4f3c\u4e8eUNIX\u6216\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u7684\u661f\u53f7<code>*<\/code><\/p>\n<p>\u4ee5\u4e0b\u662f<code>SQL SELECT<\/code>\u8bed\u53e5\u4f7f\u7528<code>LIKE<\/code>\u5b50\u53e5\u4ece\u6570\u636e\u8868\u4e2d\u8bfb\u53d6\u6570\u636e\u7684\u901a\u7528\u8bed\u6cd5\uff1a<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-sql\">SELECT field1, field2,...fieldN \nFROM table_name\nWHERE field1 LIKE condition1 [AND [OR]] filed2 = &#039;somevalue&#039;<\/code><\/pre>\n<p>\u5728<code>where like<\/code>\u7684\u6761\u4ef6\u67e5\u8be2\u4e2d\uff0cSQL \u63d0\u4f9b\u4e86\u56db\u79cd\u5339\u914d\u65b9\u5f0f<\/p>\n<ul>\n<li><code>%<\/code>\uff1a\u8868\u793a\u4efb\u610f 0 \u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\u3002\u53ef\u5339\u914d\u4efb\u610f\u7c7b\u578b\u548c\u957f\u5ea6\u7684\u5b57\u7b26\uff0c\u6709\u4e9b\u60c5\u51b5\u4e0b\u82e5\u662f\u4e2d\u6587\uff0c\u8bf7\u4f7f\u7528\u4e24\u4e2a\u767e\u5206\u53f7\uff08<code>%%<\/code>\uff09\u8868\u793a<\/li>\n<li><code>_<\/code>\uff1a\u8868\u793a\u4efb\u610f\u5355\u4e2a\u5b57\u7b26\u3002\u5339\u914d\u5355\u4e2a\u4efb\u610f\u5b57\u7b26\uff0c\u5b83\u5e38\u7528\u6765\u9650\u5236\u8868\u8fbe\u5f0f\u7684\u5b57\u7b26\u957f\u5ea6\u8bed\u53e5<\/li>\n<li><code>[]<\/code>\uff1a\u8868\u793a\u62ec\u53f7\u5185\u6240\u5217\u5b57\u7b26\u4e2d\u7684\u4e00\u4e2a\uff08\u7c7b\u4f3c\u6b63\u5219\u8868\u8fbe\u5f0f\uff09\u3002\u6307\u5b9a\u4e00\u4e2a\u5b57\u7b26\u3001\u5b57\u7b26\u4e32\u6216\u8303\u56f4\uff0c\u8981\u6c42\u6240\u5339\u914d\u5bf9\u8c61\u4e3a\u5b83\u4eec\u4e2d\u7684\u4efb\u4e00\u4e2a<\/li>\n<li><code>[^]<\/code>\uff1a\u8868\u793a\u4e0d\u5728\u62ec\u53f7\u6240\u5217\u4e4b\u5185\u7684\u5355\u4e2a\u5b57\u7b26\u3002\u5176\u53d6\u503c\u548c [] \u76f8\u540c\uff0c\u4f46\u5b83\u8981\u6c42\u6240\u5339\u914d\u5bf9\u8c61\u4e3a\u6307\u5b9a\u5b57\u7b26\u4ee5\u5916\u7684\u4efb\u4e00\u4e2a\u5b57\u7b26<\/li>\n<\/ul>\n<p>\u67e5\u8be2\u5185\u5bb9\u5305\u542b\u901a\u914d\u7b26\u65f6,\u7531\u4e8e\u901a\u914d\u7b26\u7684\u7f18\u6545\uff0c\u5bfc\u81f4\u6211\u4eec\u67e5\u8be2\u7279\u6b8a\u5b57\u7b26 <code>%<\/code>\u3001<code>_<\/code>\u3001<code>[<\/code> \u7684\u8bed\u53e5\u65e0\u6cd5\u6b63\u5e38\u5b9e\u73b0\uff0c\u800c\u628a\u7279\u6b8a\u5b57\u7b26\u7528 <code>[ ]<\/code> \u62ec\u8d77\u4fbf\u53ef\u6b63\u5e38\u67e5\u8be2\u3002<\/p>\n<p><code>like<\/code>\u5339\u914d\/\u6a21\u7cca\u5339\u914d\uff0c\u4f1a\u4e0e<code>%<\/code>\u548c<code>_<\/code>\u7ed3\u5408\u4f7f\u7528\uff1a<\/p>\n<pre><code>&#039;%a&#039; \/\/\u4ee5a\u7ed3\u5c3e\u7684\u6570\u636e\n&#039;a%&#039; \/\/\u4ee5a\u5f00\u5934\u7684\u6570\u636e\n&#039;%a%&#039; \/\/\u542b\u6709a\u7684\u6570\u636e\n&#039;_a_&#039; \/\/\u4e09\u4f4d\u4e14\u4e2d\u95f4\u5b57\u6bcd\u662fa\u7684\n&#039;_a&#039; \/\/\u4e24\u4f4d\u4e14\u7ed3\u5c3e\u5b57\u6bcd\u662fa\u7684\n&#039;a_&#039; \/\/\u4e24\u4f4d\u4e14\u5f00\u5934\u5b57\u6bcd\u662fa\u7684<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u9700\u8981\u9700\u8981\u5339\u914d\u5b57\u6bb5\u7684\u6240\u6709\u8bb0\u5f55\uff0c\u9700\u8981\u5728WHERE\u6761\u4ef6\u4e2d\u4f7f\u7528SQL LIKE\u5b50\u53e5 SQL LIKE\u5b50\u53e5\u4e2d\u4f7f\u7528\u767e\u5206\u53f7 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-233","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=233"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/233\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}