{"id":7438,"date":"2024-11-14T15:48:46","date_gmt":"2024-11-14T07:48:46","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7438\/"},"modified":"2024-11-14T15:48:46","modified_gmt":"2024-11-14T07:48:46","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-mysql-%e6%a8%a1%e7%b3%8a%e6%9f%a5%e8%af%a2%e5%8c%b9%e9%85%8d%e9%95%bf%e5%9c%b0%e5%9d%80%e4%b8%ad%e7%9a%84%e9%95%87%e5%8c%ba%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7438\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 MySQL \u6a21\u7cca\u67e5\u8be2\u5339\u914d\u957f\u5730\u5740\u4e2d\u7684\u9547\u533a\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173085596049272.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 MySQL \u6a21\u7cca\u67e5\u8be2\u5339\u914d\u957f\u5730\u5740\u4e2d\u7684\u9547\u533a\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 MySQL \u6a21\u7cca\u67e5\u8be2\u5339\u914d\u957f\u5730\u5740\u4e2d\u7684\u9547\u533a\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong> \u957f\u5730\u5740\u6a21\u7cca\u67e5\u8be2\u5339\u914d\u9547\u533a<\/strong><\/p>\n<p>\u5728 mysql \u4e2d\uff0c\u901a\u8fc7\u6a21\u7cca\u67e5\u8be2\u5339\u914d\u957f\u5730\u5740\u4e2d\u7684\u9547\u533a\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 locate() \u6216 position() \u51fd\u6570\u3002<\/p>\n<p><strong>\u95ee\u9898\u8bf4\u660e\uff1a<\/strong><\/p>\n<p>\u7ed9\u5b9a\u5982\u4e0b\u8868\u683c\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>id<\/th>\n<th>town<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>\u4e1c\u9547<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>\u897f\u9547<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>\u5357\u9547<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>\u5317\u9547<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u9700\u8981\u4ece\u8868\u4e2d\u67e5\u8be2\u51fa\u4e0e\u4ee5\u4e0b\u5730\u5740\u4e2d\u5339\u914d\u7684\u9547\u533a\uff1a\u201c\u5317\u4eac\u5e02\u671d\u9633\u533a\u4e1c\u9547\u5e78\u798f\u5c0f\u533a6\u5e625\u697c401\u623f\u201d\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528 locate() \u6216 position() \u51fd\u6570\u8fdb\u884c\u6a21\u7cca\u67e5\u8be2\uff1a<\/p>\n<pre>SELECT town\nFROM table_name\nWHERE LOCATE('\u4e1c\u9547', address) &gt; 0;\n\n-- \u6216\n\nSELECT town\nFROM table_name\nWHERE POSITION('\u4e1c\u9547' IN address) &gt; 0;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e0a\u9762\u7684\u67e5\u8be2\u8bed\u53e5\u4f1a\u8fd4\u56de \u201c\u4e1c\u9547\u201d \u8bb0\u5f55\uff0c\u56e0\u4e3a \u201c\u4e1c\u9547\u201d \u5b57\u7b26\u4e32\u5728\u7ed9\u5b9a\u5730\u5740\u4e2d\u5b58\u5728\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 MySQL \u6a21\u7cca\u67e5\u8be2\u5339\u914d\u957f\u5730\u5740\u4e2d\u7684\u9547\u533a\uff1f\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>\u957f\u5730\u5740\u6a21\u7cca\u67e5\u8be2\u5339\u914d\u9547\u533a \u5728 mysql \u4e2d\uff0c\u901a\u8fc7\u6a21\u7cca\u67e5\u8be2\u5339\u914d\u957f\u5730\u5740\u4e2d\u7684\u9547\u533a\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 locate() \u6216 position() \u51fd\u6570\u3002 \u95ee\u9898\u8bf4\u660e\uff1a \u7ed9\u5b9a\u5982\u4e0b\u8868\u683c\uff1a id town 1 \u4e1c\u9547 2 \u897f\u9547 3 \u5357\u9547 4 \u5317\u9547 \u9700\u8981\u4ece\u8868\u4e2d\u67e5\u8be2\u51fa\u4e0e\u4ee5\u4e0b\u5730\u5740\u4e2d\u5339\u914d\u7684\u9547\u533a\uff1a\u201c\u5317\u4eac\u5e02\u671d\u9633\u533a\u4e1c\u9547\u5e78\u798f\u5c0f\u533a6\u5e625\u697c401\u623f\u201d\u3002 \u89e3\u51b3\u65b9\u6cd5\uff1a \u53ef\u4ee5\u4f7f\u7528 locate() \u6216 position() \u51fd\u6570\u8fdb\u884c\u6a21\u7cca\u67e5\u8be2\uff1a SELECT town FROM table_name WHERE LOCATE(&#8216;\u4e1c\u9547&#8217;, address) &gt; 0; &#8212; \u6216 SELECT town FROM table_name WHERE POSITION(&#8216;\u4e1c\u9547&#8217; IN address) &gt; 0; \u767b\u5f55\u540e\u590d\u5236 \u4e0a\u9762\u7684\u67e5\u8be2\u8bed\u53e5\u4f1a\u8fd4\u56de \u201c\u4e1c\u9547\u201d \u8bb0\u5f55\uff0c\u56e0\u4e3a \u201c\u4e1c\u9547\u201d \u5b57\u7b26\u4e32\u5728\u7ed9\u5b9a\u5730\u5740\u4e2d\u5b58\u5728\u3002 \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 [&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-7438","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7438","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=7438"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7438\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}