{"id":6595,"date":"2024-11-14T14:33:45","date_gmt":"2024-11-14T06:33:45","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6595\/"},"modified":"2024-11-14T14:33:45","modified_gmt":"2024-11-14T06:33:45","slug":"mysql-contains%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6595\/","title":{"rendered":"mysql contains\u7528\u6cd5"},"content":{"rendered":"<blockquote><p>\n  mysql \u7684 contains \u51fd\u6570\u7528\u4e8e\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u5305\u542b\u5b50\u5b57\u7b26\u4e32\u3002\u5b83\u8fd4\u56de\u5e03\u5c14\u503c\uff0c\u8868\u793a\u5305\u542b\u6216\u4e0d\u5305\u542b\u3002\u7528\u6cd5\u5305\u62ec\uff1a\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u5305\u542b\u5b50\u5b57\u7b26\u4e32\uff08true\uff09\uff0c\u6216\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u4e0d\u5305\u542b\u5b50\u5b57\u7b26\u4e32\uff08false\uff09\u3002\u793a\u4f8b\u5305\u62ec\uff1a\u68c0\u67e5\u4ea7\u54c1\u540d\u79f0\u662f\u5426\u5305\u542b\u7279\u5b9a\u5355\u8bcd\u6216\u68c0\u67e5\u8bc4\u8bba\u662f\u5426\u5305\u542b\u7279\u5b9a\u77ed\u8bed\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8be5\u51fd\u6570\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u4e14\u4e0d\u652f\u6301\u901a\u914d\u7b26\uff0c\u6027\u80fd\u53ef\u80fd\u56e0\u5b57\u7b26\u4e32\u5927\u5c0f\u800c\u5f02\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/06\/2024080618454394596.jpg\" class=\"aligncenter\" title=\"mysql contains\u7528\u6cd5\u63d2\u56fe\" alt=\"mysql contains\u7528\u6cd5\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u4e2d CONTAINS \u7528\u6cd5<\/strong><\/p>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p>CONTAINS \u662f MySQL \u4e2d\u7684\u4e00\u4e2a\u51fd\u6570\uff0c\u7528\u4e8e\u68c0\u67e5\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u5305\u542b\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\u5b83\u8fd4\u56de\u4e00\u4e2a\u5e03\u5c14\u503c\uff0c\u8868\u793a True\uff08\u5305\u542b\uff09\u6216 False\uff08\u4e0d\u5305\u542b\uff09\u3002<\/p>\n<p><strong>\u8bed\u6cd5<\/strong><\/p>\n<pre>CONTAINS(string, substring)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u53c2\u6570<\/strong><\/p>\n<ul>\n<li> <strong>string\uff1a<\/strong>\u8981\u641c\u7d22\u7684\u5b57\u7b26\u4e32\u3002<\/li>\n<li> <strong>substring\uff1a<\/strong>\u8981\u67e5\u627e\u7684\u5b50\u5b57\u7b26\u4e32\u3002<\/li>\n<\/ul>\n<p><strong>\u7528\u6cd5<\/strong><\/p>\n<p>CONTAINS \u51fd\u6570\u7684\u7528\u6cd5\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li><strong>\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u5305\u542b\u5b50\u5b57\u7b26\u4e32\uff1a<\/strong><\/li>\n<\/ul>\n<pre>SELECT CONTAINS('Hello World', 'World');\n-- \u8f93\u51fa\uff1aTrue<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li><strong>\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u4e0d\u5305\u542b\u5b50\u5b57\u7b26\u4e32\uff1a<\/strong><\/li>\n<\/ul>\n<pre>SELECT CONTAINS('Hello World', 'Goodbye');\n-- \u8f93\u51fa\uff1aFalse<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528 CONTAINS \u51fd\u6570\uff1a<\/p>\n<pre>-- \u68c0\u67e5\u4e00\u4e2a\u4ea7\u54c1\u540d\u79f0\u662f\u5426\u5305\u542b\u7279\u5b9a\u5355\u8bcd\nSELECT product_name\nFROM products\nWHERE CONTAINS(product_name, 'Computer');\n\n-- \u68c0\u67e5\u4e00\u4e2a\u8bc4\u8bba\u662f\u5426\u5305\u542b\u7279\u5b9a\u7684\u77ed\u8bed\nSELECT review_text\nFROM reviews\nWHERE CONTAINS(review_text, 'Great customer service');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>CONTAINS \u51fd\u6570\u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff0c\u56e0\u6b64\u5b83\u5c06 &#8220;Hello&#8221; \u548c &#8220;hello&#8221; \u89c6\u4e3a\u76f8\u540c\u3002<\/li>\n<li>CONTAINS \u51fd\u6570\u4e0d\u652f\u6301\u901a\u914d\u7b26\uff0c\u56e0\u6b64\u60a8\u9700\u8981\u77e5\u9053\u8981\u67e5\u627e\u7684\u5b50\u5b57\u7b26\u4e32\u7684\u7cbe\u786e\u5185\u5bb9\u3002<\/li>\n<li>CONTAINS \u51fd\u6570\u7684\u6027\u80fd\u53ef\u80fd\u4f1a\u56e0\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\u800c\u5f02\u3002\u5bf9\u4e8e\u5927\u578b\u5b57\u7b26\u4e32\uff0c\u4f7f\u7528 LIKE \u64cd\u4f5c\u7b26\u53ef\u80fd\u66f4\u6709\u6548\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f contains\u7528\u6cd5\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>mysql \u7684 contains \u51fd\u6570\u7528\u4e8e\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u5305\u542b\u5b50\u5b57\u7b26\u4e32\u3002\u5b83\u8fd4\u56de\u5e03\u5c14\u503c\uff0c\u8868\u793a\u5305\u542b\u6216\u4e0d\u5305\u542b\u3002\u7528\u6cd5\u5305\u62ec\uff1a\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u5305\u542b\u5b50\u5b57\u7b26\u4e32\uff08true\uff09\uff0c\u6216\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u4e0d\u5305\u542b\u5b50\u5b57\u7b26\u4e32\uff08false\uff09\u3002\u793a\u4f8b\u5305\u62ec\uff1a\u68c0\u67e5\u4ea7\u54c1\u540d\u79f0\u662f\u5426\u5305\u542b\u7279\u5b9a\u5355\u8bcd\u6216\u68c0\u67e5\u8bc4\u8bba\u662f\u5426\u5305\u542b\u7279\u5b9a\u77ed\u8bed\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8be5\u51fd\u6570\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u4e14\u4e0d\u652f\u6301\u901a\u914d\u7b26\uff0c\u6027\u80fd\u53ef\u80fd\u56e0\u5b57\u7b26\u4e32\u5927\u5c0f\u800c\u5f02\u3002 MySQL \u4e2d CONTAINS \u7528\u6cd5 \u7b80\u4ecb CONTAINS \u662f MySQL \u4e2d\u7684\u4e00\u4e2a\u51fd\u6570\uff0c\u7528\u4e8e\u68c0\u67e5\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u5305\u542b\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\u5b83\u8fd4\u56de\u4e00\u4e2a\u5e03\u5c14\u503c\uff0c\u8868\u793a True\uff08\u5305\u542b\uff09\u6216 False\uff08\u4e0d\u5305\u542b\uff09\u3002 \u8bed\u6cd5 CONTAINS(string, substring) \u767b\u5f55\u540e\u590d\u5236 \u53c2\u6570 string\uff1a\u8981\u641c\u7d22\u7684\u5b57\u7b26\u4e32\u3002 substring\uff1a\u8981\u67e5\u627e\u7684\u5b50\u5b57\u7b26\u4e32\u3002 \u7528\u6cd5 CONTAINS \u51fd\u6570\u7684\u7528\u6cd5\u5982\u4e0b\uff1a \u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u5305\u542b\u5b50\u5b57\u7b26\u4e32\uff1a SELECT CONTAINS(&#8216;Hello World&#8217;, &#8216;World&#8217;); &#8212; \u8f93\u51fa\uff1aTrue \u767b\u5f55\u540e\u590d\u5236 \u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u4e0d\u5305\u542b\u5b50\u5b57\u7b26\u4e32\uff1a SELECT CONTAINS(&#8216;Hello World&#8217;, &#8216;Goodbye&#8217;); &#8212; \u8f93\u51fa\uff1aFalse \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b \u4ee5\u4e0b\u793a\u4f8b\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528 CONTAINS \u51fd\u6570\uff1a &#8212; \u68c0\u67e5\u4e00\u4e2a\u4ea7\u54c1\u540d\u79f0\u662f\u5426\u5305\u542b\u7279\u5b9a\u5355\u8bcd SELECT product_name FROM products WHERE CONTAINS(product_name, &#8216;Computer&#8217;); &#8212; [&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-6595","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6595","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=6595"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6595\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6595"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6595"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}