{"id":5474,"date":"2024-12-23T22:26:49","date_gmt":"2024-12-23T13:26:49","guid":{"rendered":"https:\/\/www.bold.ne.jp\/engineer-club\/?p=5474"},"modified":"2025-12-19T12:49:29","modified_gmt":"2025-12-19T03:49:29","slug":"how-to-replace-a-string-with-replace","status":"publish","type":"post","link":"https:\/\/www.bold.ne.jp\/engineer-club\/how-to-replace-a-string-with-replace","title":{"rendered":"\u3010SQL\u3011REPLACE\u3067\u6587\u5b57\u5217\u3092\u7f6e\u63db\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>REPLACE\u3092\u4f7f\u3046\u3068\u5358\u8a9e\u306e\u610f\u5473\u304b\u3089\u5bdf\u3059\u308b\u3068\u304a\u308a\u300c\u7f6e\u304d\u63db\u3048\u300d\u304c\u3067\u304d\u308b\u95a2\u6570\u3067\u3059\u3002<br \/>\n\u3064\u307e\u308a\u6587\u5b57\u5217\u306e\u4e2d\u304b\u3089\u300c\u6307\u5b9a\u3057\u305f\u6587\u5b57\u300d\u3092\u300c\u5225\u306e\u6587\u5b57\u300d\u306b\u7f6e\u63db\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u300cSQL University\u300d\u306e\u300cuniversity\u300d\u3092\u300cUniv.\u300d\u306b\u7f6e\u304d\u63db\u3048\u3089\u308c\u307e\u3059\u3002<br \/>\n\u305d\u308c\u3067\u306f\u3001\u4f7f\u3044\u65b9\u3092\u78ba\u8a8d\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<div id=\"toc_container\" class=\"no_bullets\"><p class=\"toc_title\">\u76ee\u6b21<\/p><ul class=\"toc_list\"><li><a href=\"#SQL_REPLACE\">\uff11\uff0eSQL REPLACE\u3067\u3067\u304d\u308b\u3053\u3068<\/a><\/li><li><a href=\"#SQL_REPLACE-2\">\uff12\uff0eSQL REPLACE\u306e\u69cb\u6587<\/a><\/li><li><a href=\"#SQL_REPLACE-3\">\uff13\uff0eSQL REPLACE\u306e\u5177\u4f53\u7684\u306a\u4f7f\u3044\u65b9<\/a><ul><li><a href=\"#i\">\uff13-\uff11\uff0e\u7279\u5b9a\u306e\u6587\u5b57\u3092\u7f6e\u63db\u3059\u308b<\/a><\/li><li><a href=\"#i-2\">\uff13-\uff12\uff0e\u6587\u5b57\u5217\u4e2d\u306e\u7279\u5b9a\u306e\u6587\u5b57\u3092\u9664\u53bb\u3059\u308b<\/a><\/li><li><a href=\"#-SUBSTRING_CONCAT\">\uff13-\uff13\uff0e\u25ef\u6587\u5b57\u76ee\u304b\u3089\u25ef\u6587\u5b57\u3092\u7f6e\u63db\u5bfe\u8c61\u3068\u3059\u308b\uff08SUBSTRING\u30fb CONCAT\u3068\u4f75\u305b\u3066\u4f7f\u7528\uff09<\/a><\/li><li><a href=\"#-UPDATE\">\uff13-\uff14\uff0eUPDATE\u3068\u5408\u308f\u305b\u3066\u4f7f\u7528\u3057\u30c6\u30fc\u30d6\u30eb\u306e\u5024\u3092\u66f4\u65b0\u3059\u308b<\/a><\/li><\/ul><\/li><li><a href=\"#i-3\">\uff14\uff0e\u3055\u3044\u3054\u306b<\/a><\/li><\/ul><\/div>\n<h2><span id=\"SQL_REPLACE\">\uff11\uff0eSQL REPLACE\u3067\u3067\u304d\u308b\u3053\u3068<\/span><\/h2>\n<p>\u6587\u5b57\u5217\u64cd\u4f5c\u3092\u304a\u3053\u306a\u3046\u95a2\u6570\u3067\u3059\u3002<br \/>\n\u6587\u5b57\u5217\u306e\u4e2d\u304b\u3089\u6307\u5b9a\u3057\u305f\u6587\u5b57\u3092\u5225\u306e\u6587\u5b57\u306b\u7f6e\u304d\u63db\u3048\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u4f8b\uff09<br \/>\n\u30fb\u300cSQL \u5927\u5b66\u300d\u3092\u300cSQL University\u300d\u306b\u7f6e\u304d\u63db\u3048\u308b<br \/>\n\u30fb\u300c123-456-7890\u300d\u306e\u30cf\u30a4\u30d5\u30f3\u3092\u9664\u53bb\u3059\u308b<br \/>\n\u30fb\u300c\u3042\u304b\u3055\u304b\u3000\u305f\u308d\u3046\u300d\u306e\u30b9\u30da\u30fc\u30b9\u3092\u9664\u53bb\u3059\u308b<\/p>\n<p><a href=\"https:\/\/www.bold.ne.jp\/engineer-club\/how-to-replace-a-string-with-replace\/%e7%94%bb%e5%83%8f1\" rel=\"attachment wp-att-5475\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2024\/12\/\u753b\u50cf1.jpg\" alt=\"REPLACE\" width=\"1366\" height=\"768\" class=\"alignnone size-full wp-image-5475\" srcset=\"https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2024\/12\/\u753b\u50cf1.jpg 1366w, https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2024\/12\/\u753b\u50cf1-1024x576.jpg 1024w, https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2024\/12\/\u753b\u50cf1-768x432.jpg 768w\" sizes=\"(max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<h2><span id=\"SQL_REPLACE-2\">\uff12\uff0eSQL REPLACE\u306e\u69cb\u6587<\/span><\/h2>\n<p>REPLACE\u306e\u69cb\u6587\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n<p>REPLACE(\u2018\u5bfe\u8c61\u306e\u6587\u5b57\u5217\u2019\uff08\u307e\u305f\u306f\u30ab\u30e9\u30e0\u540d\uff09, &#8216;\u7f6e\u63db\u524d\u306e\u6587\u5b57\u5217&#8217;, &#8216;\u7f6e\u63db\u5f8c\u306e\u6587\u5b57\u5217&#8217;)<\/p>\n<p>\u4f8b\u3048\u3070\u6b21\u306eSQL\u6587\u3067\u306f<br \/>\n\u300cABC12345678ABC\u300d\u5185\u306e\u6587\u5b57\u5217\u300cABC\u300d\u3092\u300cXYZ\u300d\u306b\u7f6e\u304d\u63db\u3048\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">SELECT REPLACE('ABC12345678ABC', 'ABC', 'XYZ')<\/pre>\n<p>SELECT\u7d50\u679c<\/p>\n<p>+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n| REPLACE(&#8216;ABC12345678ABC&#8217;, &#8216;ABC&#8217;, &#8216;XYZ&#8217;) |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n| XYZ12345678XYZ |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n1 row in set (0.00 sec)<\/p>\n<p><a href=\"https:\/\/www.bold.ne.jp\/engineer-club\/how-to-replace-a-string-with-replace\/%e7%94%bb%e5%83%8f2\" rel=\"attachment wp-att-5476\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2024\/12\/\u753b\u50cf2.png\" alt=\"REPLACE2\" width=\"1200\" height=\"600\" class=\"alignnone size-full wp-image-5476\" srcset=\"https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2024\/12\/\u753b\u50cf2.png 1200w, https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2024\/12\/\u753b\u50cf2-1024x512.png 1024w, https:\/\/www.bold.ne.jp\/engineer-club\/wp-content\/uploads\/2024\/12\/\u753b\u50cf2-768x384.png 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/a><\/p>\n<h2><span id=\"SQL_REPLACE-3\">\uff13\uff0eSQL REPLACE\u306e\u5177\u4f53\u7684\u306a\u4f7f\u3044\u65b9<\/span><\/h2>\n<p>\u305d\u308c\u3067\u306f\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3068\u5171\u306b\u5177\u4f53\u7684\u306a\u4f7f\u3044\u65b9\u3092\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3><span id=\"i\">\uff13-\uff11\uff0e\u7279\u5b9a\u306e\u6587\u5b57\u3092\u7f6e\u63db\u3059\u308b<\/span><\/h3>\n<p>\u6700\u521d\u306f\u57fa\u672c\u7684\u306a\u4f7f\u7528\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n<p>\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<br \/>\n\u4f7f\u7528\u4f8b\uff1a<br \/>\n\u300c\u88fd\u54c1A2000\u300d\u306f\u300c\u88fd\u54c1A1000\u300d\u306e\u5f8c\u7d99\u5546\u54c1\u3067\u3042\u308b\u3002<br \/>\nsales_list\u30c6\u30fc\u30d6\u30eb\u4e0a\u306f\u5225\u540d\u3067\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u304c\u300c\u88fd\u54c1A1000\u300d\u300c\u88fd\u54c1A2000\u300d\u5171\u306b<br \/>\n\u300c\u88fd\u54c1A2000\u300d\u3068\u3057\u3066SELECT\u3057\u305f\u3044\u3002<br \/>\n\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><strong><\/strong><span class=\"f-marker-p\"><strong>\u25c6sales_list \u30c6\u30fc\u30d6\u30eb<\/strong><\/span><\/p>\n<table style=\"border-collapse: collapse; width: 100%;\">\n<tbody>\n<tr>\n<td style=\"width: 20%;\">customer_name<\/td>\n<td style=\"width: 20%;\">product<\/td>\n<td style=\"width: 20%;\">quantity<\/td>\n<td style=\"width: 20%;\">price<\/td>\n<td style=\"width: 20%;\">order_date<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 20%;\">AAA\u682a\u5f0f\u4f1a\u793e<\/td>\n<td style=\"width: 20%;\">\u88fd\u54c1A1000<\/td>\n<td style=\"width: 20%;\">167<\/td>\n<td style=\"width: 20%;\">12000<\/td>\n<td style=\"width: 20%;\">2024\/3\/10<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 20%;\">ABC\u682a\u5f0f\u4f1a\u793e<\/td>\n<td style=\"width: 20%;\">\u88fd\u54c1A2000<\/td>\n<td style=\"width: 20%;\">280<\/td>\n<td style=\"width: 20%;\">12300<\/td>\n<td style=\"width: 20%;\">2024\/10\/11<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 20%;\">\u682a\u5f0f\u4f1a\u793eXX<\/td>\n<td style=\"width: 20%;\">\u88fd\u54c1B<\/td>\n<td style=\"width: 20%;\">110<\/td>\n<td style=\"width: 20%;\">19000<\/td>\n<td style=\"width: 20%;\">2024\/4\/8<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 20%;\">\u682a\u5f0f\u4f1a\u793eYY<\/td>\n<td style=\"width: 20%;\">\u88fd\u54c1C<\/td>\n<td style=\"width: 20%;\">76<\/td>\n<td style=\"width: 20%;\">80000<\/td>\n<td style=\"width: 20%;\">2024\/6\/20<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 20%;\">ZZ\u682a\u5f0f\u4f1a\u793e<\/td>\n<td style=\"width: 20%;\">\u88fd\u54c1AB1000<\/td>\n<td style=\"width: 20%;\">160<\/td>\n<td style=\"width: 20%;\">600<\/td>\n<td style=\"width: 20%;\">2024\/5\/7<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre class=\"prettyprint lang:default decode:true\">SELECT\r\n  customer_name, \r\n  REPLACE(product, '\u88fd\u54c1A1000',  '\u88fd\u54c1A2000') as product,\r\n  quantity, \r\n  price, \r\n  order_date \r\nFROM sales_list;\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>SELECT \u7d50\u679c<\/p>\n<p>+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br \/>\n| customer_name | product | quantity | price | order_date |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br \/>\n| AAA\u682a\u5f0f\u4f1a\u793e | \u88fd\u54c1A2000 | 167 | 12000 | 2024-03-10 00:00:00 |<br \/>\n| ABC\u682a\u5f0f\u4f1a\u793e | \u88fd\u54c1A2000 | 280 | 12300 | 2024-10-11 00:00:00 |<br \/>\n| \u682a\u5f0f\u4f1a\u793eXX | \u88fd\u54c1B | 110 | 19000 | 2024-04-08 00:00:00 |<br \/>\n| \u682a\u5f0f\u4f1a\u793eYY | \u88fd\u54c1C | 76 | 80000 | 2024-06-20 00:00:00 |<br \/>\n| ZZ\u682a\u5f0f\u4f1a\u793e | \u88fd\u54c1AB1000 | 160 | 600 | 2024-05-07 00:00:00 |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br \/>\n5 rows in set (0.00 sec)<\/p>\n<p>\n\u5143\u306e\u30c6\u30fc\u30d6\u30eb\u3067\u306f\u300cAAA\u682a\u5f0f\u4f1a\u793e\u300d\u306eproduct\u306f\u300c\u88fd\u54c1A1000\u300d\u3067\u3059\u304c\u3001REPLACE\u5f8c\u306eSELECT\u7d50\u679c\u3067\u306f\u300c\u88fd\u54c1A2000\u300d\u306b\u7f6e\u63db\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u3068\u304d\u3001\u300c1000\u300d\u3092\u300c2000\u300d\u306bREPLACE\u3059\u308b\u3088\u3046\u306aSQL\u6587\u3092\u8a18\u8ff0\u3057\u3066\u3057\u307e\u3046\u3068\u300c\u88fd\u54c1AB1000\u300d\u306e\u5024\u3082\u7f6e\u63db\u3055\u308c\u3066\u3057\u307e\u3046\u305f\u3081\u3001\u7f6e\u63db\u524d\u306e\u5024\u306e\u6307\u5b9a\u306b\u306f\u5145\u5206\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3><span id=\"i-2\">\uff13-\uff12\uff0e\u6587\u5b57\u5217\u4e2d\u306e\u7279\u5b9a\u306e\u6587\u5b57\u3092\u9664\u53bb\u3059\u308b<\/span><\/h3>\n<p>\u6307\u5b9a\u306e\u6587\u5b57\u3092\u2018\u2019\u3067\u7f6e\u63db\u3059\u308b\u3053\u3068\u306b\u3088\u308a\u3001\u6307\u5b9a\u306e\u6587\u5b57\u3092\u53d6\u308a\u9664\u304f\u3068\u3044\u3046\u4f7f\u3044\u65b9\u3092\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<br \/>\n\u4f7f\u7528\u4f8b\uff1a<br \/>\ncustomer_list\u30c6\u30fc\u30d6\u30eb\u306e\u9867\u5ba2ID\u306e\u30cf\u30a4\u30d5\u30f3\u3092\u53d6\u308a\u9664\u304d\u3001\u6570\u5b57\u306e\u307f\u306eCustomerID\u3092\u53d6\u5f97\u3057\u305f\u3044<br \/>\n\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><strong><\/strong><span class=\"f-marker-p\"><strong>\u25c6 customer_list\u30c6\u30fc\u30d6\u30eb<\/strong><\/span><\/p>\n<table style=\"border-collapse: collapse; width: 100%;\">\n<tbody>\n<tr>\n<td style=\"width: 50%;\">customer_name<\/td>\n<td style=\"width: 50%;\">CustomerID<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\">AAA\u682a\u5f0f\u4f1a\u793e<\/td>\n<td style=\"width: 50%;\">0000-111-2222<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\">ABC\u682a\u5f0f\u4f1a\u793e<\/td>\n<td style=\"width: 50%;\">0000-111-2223<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\">\u682a\u5f0f\u4f1a\u793eXX<\/td>\n<td style=\"width: 50%;\">0000-111-2224<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\">\u682a\u5f0f\u4f1a\u793eYY<\/td>\n<td style=\"width: 50%;\">0000-111-2225<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\">ZZ\u682a\u5f0f\u4f1a\u793e<\/td>\n<td style=\"width: 50%;\">0000-111-2226<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\">\u682a\u5f0f\u4f1a\u793eXYZ<\/td>\n<td style=\"width: 50%;\">1111-111-2226<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre class=\"prettyprint lang:default decode:true\">SELECT \r\n  customer_name,\r\n  REPLACE(customerID, '-', '') as customerID\r\nFROM customer_list;\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>SELECT\u7d50\u679c<\/p>\n<p>+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+<br \/>\n| customer_name | customerID |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+<br \/>\n| AAA\u682a\u5f0f\u4f1a\u793e | 00001112222 |<br \/>\n| ABC\u682a\u5f0f\u4f1a\u793e | 00001112223 |<br \/>\n| \u682a\u5f0f\u4f1a\u793eXX | 00001112224 |<br \/>\n| \u682a\u5f0f\u4f1a\u793eYY | 00001112225 |<br \/>\n| ZZ\u682a\u5f0f\u4f1a\u793e | 00001112225 |<br \/>\n| \u682a\u5f0f\u4f1a\u793eXYZ | 11111112227 |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+<br \/>\n6 rows in set (0.00 sec)<\/p>\n<p>\u30cf\u30a4\u30d5\u30f3\u3092\u9664\u53bb\u3057\u3001\u6570\u5b57\u306e\u307f\u306e\u9867\u5ba2ID\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<h3><span id=\"-SUBSTRING_CONCAT\">\uff13-\uff13\uff0e\u25ef\u6587\u5b57\u76ee\u304b\u3089\u25ef\u6587\u5b57\u3092\u7f6e\u63db\u5bfe\u8c61\u3068\u3059\u308b\uff08<span>SUBSTRING<\/span>\u30fb<span> CONCAT<\/span>\u3068\u4f75\u305b\u3066\u4f7f\u7528\uff09<\/span><\/h3>\n<p>\u5fdc\u7528\u7de8\u3068\u3057\u3066\u7279\u5b9a\u306e\u5834\u6240\u306b\u3042\u308b\u6307\u5b9a\u306e\u6587\u5b57\u3092\u7f6e\u304d\u63db\u3048\u308b\u65b9\u6cd5\u3067\u3059\u3002<br \/>\n\u5148\u7a0b\u3082\u8ff0\u3079\u307e\u3057\u305f\u304c\u3001\u4e0d\u7528\u610f\u306bREPLACE\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u601d\u308f\u306c\u7b87\u6240\u3082\u66f8\u304d\u63db\u308f\u3063\u3066\u3057\u307e\u3046\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u4e00\u5b9a\u306e\u30eb\u30fc\u30eb\u306b\u57fa\u3065\u3044\u3066\u7f6e\u63db\u5bfe\u8c61\u304c\u5b58\u5728\u3059\u308b\u5834\u5408\u3001SUBSTRING\u3068\u7d44\u307f\u5408\u308f\u305b\u308b\u65b9\u6cd5\u304c\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002<br \/>\n\u4f8b\u3048\u3070\u5148\u7a0b\u306ecustomer_list\u30c6\u30fc\u30d6\u30eb\u306e\u9867\u5ba2ID\u306e\u50246\u301c8\u6587\u5b57\u76ee\u306e\u300c111\u300d\u3092\u300cAAA\u300d\u306b\u7f6e\u63db\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<br \/>\n\u4f7f\u7528\u4f8b\uff1a<br \/>\ncustomer_list\u30c6\u30fc\u30d6\u30eb\u306ecustomer ID \u306e6\u6587\u5b57\u76ee\u304b\u30898\u6587\u5b57\u76ee\u306e\u300c111\u300d\u3092\u300cAAA\u300d\u306b\u7f6e\u63db\u3057\u305f\u3044<br \/>\n\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p>\u5358\u7d14\u306bREPLACE\u3092\u3059\u308b\u3068\u5bfe\u8c61\u5916\u3068\u3057\u305f\u3044\u6587\u5b57\u5217\u3082\u7f6e\u63db\u3055\u308c\u3066\u3057\u307e\u3046\u305f\u3081\u5c11\u3057\u5de5\u592b\u304c\u5fc5\u8981\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>ex\uff09\u3000\u682a\u5f0f\u4f1a\u793eXYZ 1111-111-2226\u3000\u2192\u30001111-111-2226\u3000\u5148\u982d\u306e\u300c1111-\u300d\u306f\u7f6e\u63db\u5bfe\u8c61\u5916\u3068\u3057\u305f\u3044<\/p>\n<p>\u65b9\u6cd5\u306f\u3044\u304f\u3064\u304b\u8003\u3048\u3089\u308c\u307e\u3059\u304c\u3001\u3053\u306e\u4f8b\u3067\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u51e6\u7406\u3092\u3057\u307e\u3059\u3002<\/p>\n<p>\u2460 SUBSTRING\u3000\u3092\u4f7f\u7528\u3057\u3066\u5148\u982d\u306e5\u6587\u5b57\u3092\u53d6\u5f97\u3059\u308b\u3000\u2190\u3053\u306e\u90e8\u5206\u306f\u7f6e\u63db\u5bfe\u8c61\u5916<br \/>\n\u2461 SUBSTRING\u3000\u3092\u4f7f\u7528\u3057\u30666\u6587\u5b57\u76ee\u304b\u30898\u6587\u5b57\u76ee\u3092\u53d6\u5f97\u3001REPLACE\u3000\u3067\u300c111\u300d\u3092\u300cAAA\u300d\u306b\u7f6e\u63db\u3059\u308b<br \/>\n\u2462 SUBSTRING\u3000\u3092\u4f7f\u7528\u3057\u30669\u6587\u5b57\u76ee\u4ee5\u964d\u3092\u53d6\u5f97\u3059\u308b<br \/>\n\u2463 CONCAT \u3092\u4f7f\u7528\u3057\u3066\u4e0a\u8a18\u2460\u304b\u3089\u2462\u306e\u6587\u5b57\u5217\u3092\u7d50\u5408\u3059\u308b<\/p>\n<pre class=\"prettyprint lang:default decode:true\">SELECT \r\n  customer_name,\r\n  CONCAT(\r\nSUBSTRING(customerID, 1, 5) , \r\nREPLACE(SUBSTRING(customerID, 6,3),'111','AAA'),\r\nSUBSTRING(customerID, 9)\r\n) as customerID\r\nFROM customer_list;\r\n<\/pre>\n<p>SELECT\u7d50\u679c<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;+<br \/>\n| customer_name | customerID |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;+<br \/>\n| AAA\u682a\u5f0f\u4f1a\u793e | 0000-AAA-2222 |<br \/>\n| ABC\u682a\u5f0f\u4f1a\u793e | 0000-AAA-2223 |<br \/>\n| \u682a\u5f0f\u4f1a\u793eXX | 0000-AAA-2224 |<br \/>\n| \u682a\u5f0f\u4f1a\u793eYY | 0000-AAA-2225 |<br \/>\n| ZZ\u682a\u5f0f\u4f1a\u793e | 0000-AAA-2225 |<br \/>\n| \u682a\u5f0f\u4f1a\u793eXYZ | 1111-AAA-2227 |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;+<br \/>\n6 rows in set (0.00 sec)<\/p>\n<p>6\u6587\u5b57\u76ee\u304b\u30898\u6587\u5b57\u76ee\u3092REPLACE\u306e\u5bfe\u8c61\u3068\u3057\u3066\u3044\u308b\u305f\u3081\u3001\u682a\u5f0f\u4f1a\u793eXYZ\u306e\u9867\u5ba2ID\u5148\u982d\u306e\u300c1111-\u300d\u306f\u300cAAA1-\u300d\u306b\u7f6e\u63db\u3055\u308c\u308b\u3053\u3068\u306a\u304f\u300c1111-AAA-2227\u300d\u3068\u3044\u3046\u9867\u5ba2ID\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u3053\u3067\u306fSUBSTRING\u30fbCONCAT\u306e\u8a73\u7d30\u306f\u8a18\u8f09\u3057\u307e\u305b\u3093\u304c\u3001\u69d8\u3005\u306a\u95a2\u6570\u3068\u7d44\u307f\u5408\u308f\u305b\u3066\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u610f\u56f3\u3057\u306a\u3044\u7f6e\u63db\u304c\u884c\u308f\u308c\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u203bSUBSTRING\u3000\u306fDBMS\u306b\u3088\u308a\u8868\u8a18\u304c\u7570\u306a\u308a\u307e\u3059\u3002\u8a73\u7d30\u306f\u304a\u4f7f\u3044\u306eDB\u540d\u3067\u691c\u7d22\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3><span id=\"-UPDATE\">\uff13-\uff14\uff0eUPDATE\u3068\u5408\u308f\u305b\u3066\u4f7f\u7528\u3057\u30c6\u30fc\u30d6\u30eb\u306e\u5024\u3092\u66f4\u65b0\u3059\u308b<\/span><\/h3>\n<p>\u3053\u3053\u307e\u3067\u306eSQL\u3067\u306f\u3042\u304f\u307e\u3067\u3082SELECT\u7d50\u679c\u306b\u5bfe\u3057\u3066\u7f6e\u63db\u3092\u3057\u3066\u3044\u307e\u3059\u306e\u3067DB\u306e\u30c6\u30fc\u30d6\u30eb\u4e0a\u306e\u5024\u306b\u5909\u5316\u306f\u3042\u308a\u307e\u305b\u3093\u3002<br \/>\n\u30c6\u30fc\u30d6\u30eb\u306e\u5024\u3092\u66f4\u65b0\u3059\u308b\u306b\u306f\u3001UPDATE\u6587\u3068\u7d44\u307f\u5408\u308f\u305b\u3066\u4f7f\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h2><span id=\"i-3\">\uff14\uff0e\u3055\u3044\u3054\u306b<\/span><\/h2>\n<p>REPLACE\u95a2\u6570\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3057\u305f\u3002<br \/>\n\u4ed6\u306b\u3082\u300c\u6f22\u5b57\u3068\u3072\u3089\u304c\u306a\u306e\u8868\u8a18\u63fa\u308c\u7d71\u4e00\u300d\u306a\u3069\u3001REPLACE\u95a2\u6570\u306e\u4f7f\u3044\u3069\u3053\u308d\u306f\u305f\u304f\u3055\u3093\u3042\u308a\u307e\u3059\u304c\u3001\u610f\u56f3\u3057\u306a\u3044\u7f6e\u63db\u304c\u304a\u3053\u306a\u308f\u308c\u306a\u3044\u3088\u3046\u306a\u5de5\u592b\u3082\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<p>\u6700\u5f8c\u307e\u3067\u304a\u8aad\u307f\u3044\u305f\u3060\u304d\u307e\u3057\u3066\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u3010\u52d5\u4f5c\u691c\u8a3cDB\u3011<br \/>\nmySQL 8.0.39<\/p>\n","protected":false},"excerpt":{"rendered":"<p>REPLACE\u3092\u4f7f\u3046\u3068\u5358\u8a9e\u306e\u610f\u5473\u304b\u3089\u5bdf\u3059\u308b\u3068\u304a\u308a\u300c\u7f6e\u304d\u63db\u3048\u300d\u304c\u3067\u304d\u308b\u95a2\u6570\u3067\u3059\u3002 \u3064\u307e\u308a\u6587\u5b57\u5217\u306e\u4e2d\u304b\u3089\u300c\u6307\u5b9a\u3057\u305f\u6587\u5b57\u300d\u3092\u300c\u5225\u306e\u6587\u5b57\u300d\u306b\u7f6e\u63db\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 \u4f8b\u3048\u3070\u300cSQL University\u300d\u306e\u300cuniversity [&hellip;]<\/p>\n","protected":false},"author":28,"featured_media":5401,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts\/5474"}],"collection":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/users\/28"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/comments?post=5474"}],"version-history":[{"count":8,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts\/5474\/revisions"}],"predecessor-version":[{"id":6278,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts\/5474\/revisions\/6278"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/media\/5401"}],"wp:attachment":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/media?parent=5474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/categories?post=5474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}