求助MYSQL批量替换或删除两个字符之间内容的语句
发布网友
发布时间:2022-04-07 17:52
我来回答
共1个回答
热心网友
时间:2022-04-07 19:21
mysql> set @str := "xxxxxxxxxxxxxxxx <p>123</p> 这里内容不定<p>456</p> xxxxxxxxxxxxxxxxxxxxx";
Query OK, 0 rows affected (0.00 sec)
mysql> select @str;
+--------------------------------------------------------------------------+
| @str |
+--------------------------------------------------------------------------+
| xxxxxxxxxxxxxxxx <p>123</p> 这里内容不定<p>456</p> xxxxxxxxxxxxxxxxxxxxx |
+--------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select replace(@str, substring_index(substring_index(@str, "<p>123</p>",-1), "<p>456</p>", 1), "替换的内容,或者变为空字符串就是删除");
+----------------------------------------------------------------------------------------------------------------------------------+
| replace(@str, substring_index(substring_index(@str, "<p>123</p>", -1), "<p>456</p>", 1), "替换的内容,或者变为空字符串就是删除") |
+----------------------------------------------------------------------------------------------------------------------------------+
| xxxxxxxxxxxxxxxx <p>123</p>替换的内容,或者变为空字符串就是删除<p>456</p> xxxxxxxxxxxxxxxxxxxxx |
+----------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
把上面的 @str 换成你的数据库的列名用在SQL语句里就可以实现效果了。