[英]Removing the first occurrence of n digits in a string in Mysql
I want to remove the first occurrence of 15 from this number.我想从此数字中删除第一次出现的 15。 I found this way to do it but surely there is a simpler way.
我找到了这种方法,但肯定有更简单的方法。
select concat(Substring_index(0180154571556, '15', 1),Substring(0180154571556,Length(concat(Substring_index(0180154571556, '15', 1),'15'))+1,length(0180154571556))) as text;
--Expected result: 1804571556 --预期结果:1804571556
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.26 |
+-----------+
mysql> select regexp_replace('0180154571556', '15', '', 1, 1) as text;
+-------------+
| text |
+-------------+
| 01804571556 |
+-------------+
See https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-replace参见https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-replace
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.