{"id":6249,"date":"2024-11-14T09:15:14","date_gmt":"2024-11-14T01:15:14","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6249\/"},"modified":"2024-11-14T09:15:14","modified_gmt":"2024-11-14T01:15:14","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8mysql%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%b8%ad%e6%8f%90%e5%8f%96%e7%9b%b8%e5%ba%94%e5%ad%97%e6%ae%b5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6249\/","title":{"rendered":"\u5982\u4f55\u5728mysql\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u76f8\u5e94\u5b57\u6bb5"},"content":{"rendered":"<blockquote><p>\n  \u4ece mysql \u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u7279\u5b9a\u5b57\u6bb5\uff1a\u786e\u5b9a\u76ee\u6807\u5b57\u6bb5\u3002\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f regexp_extract() \u5339\u914d\u5b57\u6bb5\u3002\u4f7f\u7528\u5b50\u67e5\u8be2\u63d0\u53d6\u5b57\u6bb5\u3002\u4f7f\u7528\u5b57\u7b26\u4e32\u51fd\u6570 substring() \u548c position() \u63d0\u53d6\u5b57\u6bb5\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/15\/2024061516422682292.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5728mysql\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u76f8\u5e94\u5b57\u6bb5\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728mysql\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u76f8\u5e94\u5b57\u6bb5\u63d2\u56fe\" \/><\/p>\n<h2>\u5982\u4f55\u4ece MySQL \u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u6307\u5b9a\u5b57\u6bb5<\/h2>\n<p><strong>\u6b65\u9aa4 1\uff1a\u786e\u5b9a\u76ee\u6807\u5b57\u6bb5<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u786e\u5b9a\u8981\u4ece\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u7684\u76ee\u6807\u5b57\u6bb5\u3002\u4f8b\u5982\uff0c\u5982\u679c\u5b57\u7b26\u4e32\u5305\u542b\u5730\u5740\u4fe1\u606f\uff0c\u76ee\u6807\u5b57\u6bb5\u53ef\u80fd\u662f\u8857\u9053\u3001\u57ce\u5e02\u548c\u90ae\u653f\u7f16\u7801\u3002<\/p>\n<p><strong>\u6b65\u9aa4 2\uff1a\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f<\/strong><\/p>\n<p>\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u4e00\u79cd\u7528\u4e8e\u5339\u914d\u5b57\u7b26\u4e32\u6a21\u5f0f\u7684\u5f3a\u5927\u5de5\u5177\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u4ece\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u7279\u5b9a\u5b57\u6bb5\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>regexp_extract(string, pattern, index)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>string\uff1a\u76ee\u6807\u5b57\u7b26\u4e32\u3002<\/li>\n<li>pattern\uff1a\u5339\u914d\u5b57\u6bb5\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u3002<\/li>\n<li>index\uff1a\u63d0\u53d6\u5339\u914d\u9879\u7684\u7d22\u5f15\uff08\u4ece 1 \u5f00\u59cb\uff09\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u4ece\u4e00\u4e2a\u5305\u542b\u8857\u9053\u5730\u5740\u7684\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u8857\u9053\u503c\uff1a<\/p>\n<pre>regexp_extract('123 Main Street, Anytown, CA 12345', '^(.*?)s+', 1)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b65\u9aa4 3\uff1a\u4f7f\u7528\u5b50\u67e5\u8be2<\/strong><\/p>\n<p>\u5b50\u67e5\u8be2\u53ef\u4ee5\u7528\u6765\u4ece\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u5b57\u6bb5\u3002\u5b50\u67e5\u8be2\u4e2d\u7684\u4ee3\u7801\u5c06\u8fd4\u56de\u4e00\u4e2a\u8868\uff0c\u8be5\u8868\u5305\u542b\u8981\u63d0\u53d6\u7684\u5b57\u6bb5\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>(SELECT field FROM (SELECT string AS str) WHERE str LIKE pattern)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>string\uff1a\u76ee\u6807\u5b57\u7b26\u4e32\u3002<\/li>\n<li>pattern\uff1a\u5339\u914d\u5b57\u6bb5\u7684\u6a21\u5f0f\u3002<\/li>\n<li>field\uff1a\u8981\u63d0\u53d6\u7684\u5b57\u6bb5\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u4ece\u4e00\u4e2a\u5305\u542b\u9017\u53f7\u5206\u9694\u7684\u5b57\u6bb5\u7684\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u7b2c\u4e8c\u4e2a\u5b57\u6bb5\uff1a<\/p>\n<pre>(SELECT field2 FROM (SELECT 'field1,field2,field3' AS str) WHERE str LIKE '%field2,%')<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b65\u9aa4 4\uff1a\u4f7f\u7528\u5b57\u7b26\u4e32\u51fd\u6570<\/strong><\/p>\n<p>\u5b57\u7b26\u4e32\u51fd\u6570\uff0c\u5982 SUBSTRING() \u548c POSITION()\uff0c\u4e5f\u53ef\u7528\u4e8e\u4ece\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u5b57\u6bb5\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<ul>\n<li>SUBSTRING(string, start, length)\uff1a\u63d0\u53d6\u5b57\u7b26\u4e32\u4e2d\u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u4ece start \u5f00\u59cb\uff0c\u957f\u5ea6\u4e3a length\u3002<\/li>\n<li>POSITION(substring, string)\uff1a\u8fd4\u56de substring \u5728 string \u4e2d\u9996\u6b21\u51fa\u73b0\u7684\u4f4d\u7f6e\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u4ece\u4e00\u4e2a\u5305\u542b\u7535\u5b50\u90ae\u4ef6\u5730\u5740\u7684\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u57df\uff08@ \u4e4b\u540e\u7684\uff09\uff1a<\/p>\n<pre>SUBSTRING('john@example.com', POSITION('@', 'john@example.com') + 1)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u76f8\u5e94\u5b57\u6bb5\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>\u4ece mysql \u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u7279\u5b9a\u5b57\u6bb5\uff1a\u786e\u5b9a\u76ee\u6807\u5b57\u6bb5\u3002\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f regexp_extract() \u5339\u914d\u5b57\u6bb5\u3002\u4f7f\u7528\u5b50\u67e5\u8be2\u63d0\u53d6\u5b57\u6bb5\u3002\u4f7f\u7528\u5b57\u7b26\u4e32\u51fd\u6570 substring() \u548c position() \u63d0\u53d6\u5b57\u6bb5\u3002 \u5982\u4f55\u4ece MySQL \u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u6307\u5b9a\u5b57\u6bb5 \u6b65\u9aa4 1\uff1a\u786e\u5b9a\u76ee\u6807\u5b57\u6bb5 \u9996\u5148\uff0c\u786e\u5b9a\u8981\u4ece\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u7684\u76ee\u6807\u5b57\u6bb5\u3002\u4f8b\u5982\uff0c\u5982\u679c\u5b57\u7b26\u4e32\u5305\u542b\u5730\u5740\u4fe1\u606f\uff0c\u76ee\u6807\u5b57\u6bb5\u53ef\u80fd\u662f\u8857\u9053\u3001\u57ce\u5e02\u548c\u90ae\u653f\u7f16\u7801\u3002 \u6b65\u9aa4 2\uff1a\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f \u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u4e00\u79cd\u7528\u4e8e\u5339\u914d\u5b57\u7b26\u4e32\u6a21\u5f0f\u7684\u5f3a\u5927\u5de5\u5177\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u4ece\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u7279\u5b9a\u5b57\u6bb5\u3002 \u8bed\u6cd5\uff1a regexp_extract(string, pattern, index) \u767b\u5f55\u540e\u590d\u5236 string\uff1a\u76ee\u6807\u5b57\u7b26\u4e32\u3002 pattern\uff1a\u5339\u914d\u5b57\u6bb5\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u3002 index\uff1a\u63d0\u53d6\u5339\u914d\u9879\u7684\u7d22\u5f15\uff08\u4ece 1 \u5f00\u59cb\uff09\u3002 \u793a\u4f8b\uff1a \u4ece\u4e00\u4e2a\u5305\u542b\u8857\u9053\u5730\u5740\u7684\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u8857\u9053\u503c\uff1a regexp_extract(&#8216;123 Main Street, Anytown, CA 12345&#8217;, &#8216;^(.*?)s+&#8217;, 1) \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4 3\uff1a\u4f7f\u7528\u5b50\u67e5\u8be2 \u5b50\u67e5\u8be2\u53ef\u4ee5\u7528\u6765\u4ece\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u5b57\u6bb5\u3002\u5b50\u67e5\u8be2\u4e2d\u7684\u4ee3\u7801\u5c06\u8fd4\u56de\u4e00\u4e2a\u8868\uff0c\u8be5\u8868\u5305\u542b\u8981\u63d0\u53d6\u7684\u5b57\u6bb5\u3002 \u8bed\u6cd5\uff1a (SELECT field FROM (SELECT string AS str) WHERE str LIKE pattern) \u767b\u5f55\u540e\u590d\u5236 [&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-6249","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6249","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=6249"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6249\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6249"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}