{"id":2981,"date":"2021-07-07T23:56:37","date_gmt":"2021-07-07T14:56:37","guid":{"rendered":"https:\/\/obenkyolab.com\/?p=2981"},"modified":"2022-01-24T06:48:30","modified_gmt":"2022-01-23T21:48:30","slug":"%e3%80%90mysql%e3%80%91%e7%89%b9%e5%ae%9a%e3%81%ae%e6%96%87%e5%ad%97%e3%81%a7%e6%96%87%e5%ad%97%e5%88%97%e3%82%92%e5%88%86%e5%89%b2%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/obenkyolab.com\/?p=2981","title":{"rendered":"\u3010MySQL\u3011\u7279\u5b9a\u306e\u6587\u5b57\u3067\u6587\u5b57\u5217\u3092\u5206\u5272\u3059\u308b"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_80 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/obenkyolab.com\/?p=2981\/#%E6%A6%82%E8%A6%81\" >\u6982\u8981<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/obenkyolab.com\/?p=2981\/#%E7%92%B0%E5%A2%83\" >\u74b0\u5883<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/obenkyolab.com\/?p=2981\/#%E6%BA%96%E5%82%99\" >\u6e96\u5099<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/obenkyolab.com\/?p=2981\/#SUBSTRING%E3%81%A8LOCATE%E3%81%AE%E7%B5%84%E3%81%BF%E5%90%88%E3%82%8F%E3%81%9B%E3%81%A7%E5%88%86%E5%89%B2\" >SUBSTRING\u3068LOCATE\u306e\u7d44\u307f\u5408\u308f\u305b\u3067\u5206\u5272<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%A6%82%E8%A6%81\"><\/span>\u6982\u8981<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u304a\u3044\u3066\u3001\u4e00\u3064\u306e\u30ab\u30e9\u30e0\u5185\u306b\u6587\u5b57\u5217\u304c\u5165\u3063\u3066\u304a\u308a\u3001\u7279\u5b9a\u306e\u6587\u5b57\u5217\u3067\u5206\u5272\u3057\u305f\u3044\u30b1\u30fc\u30b9\u304c\u305f\u307e\u306b\u3042\u308a\u307e\u3059\u3002\u4eca\u56de\u306fMySQL\u3067\u7279\u5b9a\u306e\u6587\u5b57\u5217\u3092\u5883\u306b\u5206\u5272\u3059\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u30e1\u30e2\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E7%92%B0%E5%A2%83\"><\/span>\u74b0\u5883<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>MySQL  5.5.62<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%BA%96%E5%82%99\"><\/span>\u6e96\u5099<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306aSQL\u3067\u30c6\u30b9\u30c8\u7528\u306e\u30c7\u30fc\u30bf\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>CREATE TABLE testdb.sltest(\n    col1 varchar(10)\n);\n\nINSERT INTO testdb.sltest (col1) VALUES (&#39;I am&#39;);\nINSERT INTO testdb.sltest (col1) VALUES (&#39;He is&#39;);\nINSERT INTO testdb.sltest (col1) VALUES (&#39;They are&#39;);<\/code><\/pre><\/div>\n\n\n\n<p>\u7d50\u679c\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30c6\u30fc\u30d6\u30eb\u3068\u30c7\u30fc\u30bf\u304c\u51fa\u6765\u4e0a\u304c\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table aligncenter is-style-regular\"><table><thead><tr><th>col1<\/th><\/tr><\/thead><tbody><tr><td>I am<\/td><\/tr><tr><td>He is<\/td><\/tr><tr><td>They are<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4eca\u56de\u306f\u6587\u5b57\u5217\u306e\u9593\u306b\u534a\u89d2\u30b9\u30da\u30fc\u30b9\u3092\u5165\u308c\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u3092\u5206\u5272\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"SUBSTRING%E3%81%A8LOCATE%E3%81%AE%E7%B5%84%E3%81%BF%E5%90%88%E3%82%8F%E3%81%9B%E3%81%A7%E5%88%86%E5%89%B2\"><\/span>SUBSTRING\u3068LOCATE\u306e\u7d44\u307f\u5408\u308f\u305b\u3067\u5206\u5272<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>SUBSTRING\u306f\u6587\u5b57\u5217\u306e\u62bd\u51fa\u304c\u3067\u304d\u308b\u95a2\u6570\u3067\u3059\u3002\u4e00\u65b9\u3001LOCATE\u306f\u7279\u5b9a\u306e\u6587\u5b57\u306e\u4f4d\u7f6e\u3092\u8fd4\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u95a2\u6570\u3067\u3059\u3002\u3053\u306e\u4e8c\u3064\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u7279\u5b9a\u306e\u6587\u5b57\u3092\u898b\u3064\u3051\u51fa\u3057\u3066\u5206\u5272\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u305d\u308c\u305e\u308c\u306e\u95a2\u6570\u306e\u5f15\u6570\u306f\u4ee5\u4e0b\u306e\u901a\u308a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>SUBSTRING(\u30ab\u30e9\u30e0\u540d, \u62bd\u51fa\u958b\u59cb\u6587\u5b57\u4f4d\u7f6e, \u62bd\u51fa\u7d42\u4e86\u6587\u5b57\u4f4d\u7f6e)<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>LOCATE(\u7279\u5b9a\u6587\u5b57, \u30ab\u30e9\u30e0\u540d)<\/li><\/ul>\n\n\n\n<p>\u7d44\u307f\u5408\u308f\u305b\u305f\u4f8b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306aSQL\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-sql\" data-lang=\"SQL\"><code>SELECT\n    col1\n    ,SUBSTRING(col1,1,LOCATE(&#39; &#39;,col1)-1) AS col2\n\t,SUBSTRING(col1,LOCATE(&#39; &#39;,col1)+1,LENGTH(col1)) AS col3\nFROM\n    testdb.sltest<\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u306e\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002\u4e3b\u8a9e\u3068\u8ff0\u8a9e\u304c\u3046\u307e\u304f\u5206\u5272\u3055\u308c\u3001\u5225\u30ab\u30e9\u30e0\u3068\u3057\u3066\u62bd\u51fa\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-regular\"><table><thead><tr><th>col1<\/th><th>col2<\/th><th>col3<\/th><\/tr><\/thead><tbody><tr><td>I am<\/td><td>I<\/td><td>am<\/td><\/tr><tr><td>He is<\/td><td>He<\/td><td>is<\/td><\/tr><tr><td>They are<\/td><td>They<\/td><td>are<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4eca\u56de\u306f\u9593\u306e\u7a7a\u767d\u304c\u4e0d\u8981\u3060\u3063\u305f\u305f\u3081\u3001LOCATE(&#8216; &#8216;,col1)-1\u3068LOCATE(&#8216; &#8216;,col1)+1\u306e\u3088\u3046\u306b\u00b11\u3067\u6587\u5b57\u4f4d\u7f6e\u3092\u8abf\u6574\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u6b8b\u3057\u305f\u3044\u5834\u5408\u306f\u3053\u306e\u5024\u30920\u306b\u3057\u3066\u3046\u307e\u304f\u8abf\u6574\u3059\u308b\u3068\u3069\u3061\u3089\u304b\u306b\u6b8b\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u4ee5\u4e0a<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981 \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u304a\u3044\u3066\u3001\u4e00\u3064\u306e\u30ab\u30e9\u30e0\u5185\u306b\u6587\u5b57\u5217\u304c\u5165\u3063\u3066\u304a\u308a\u3001\u7279\u5b9a&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":2986,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"ja","_original_post":"https:\/\/obenkyolab.com\/?p=2981","footnotes":""},"categories":[57,58],"tags":[],"class_list":["post-2981","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql","category-sql","ja"],"_links":{"self":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts\/2981","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2981"}],"version-history":[{"count":9,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts\/2981\/revisions"}],"predecessor-version":[{"id":4696,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts\/2981\/revisions\/4696"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/media\/2986"}],"wp:attachment":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2981"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2981"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2981"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}