在我的数据库MySQL上,我有以下字符串:
19-003950
从这个字符串我只需要提取
003950
并转换为:
103950
将字符串中的第一个字符“ 0”替换为“ 1”。
我已经成功尝试了以下SQL查询:
mysql> SELECT
REPLACE (
SUBSTRING_INDEX('19-003950', '-' ,- 1),
SUBSTRING(
SUBSTRING_INDEX('19-003950', '-' ,- 1),
1,
1
),
'1'
) AS NEWSTRING;
+-----------+
| NEWSTRING |
+-----------+
| 113951 |
+-----------+
1 row in set
请你能帮我吗?
考虑:
select
concat(
'1',
substring(str, locate('-', str) + 1)
) new_string
from (select '19-003950' str) t
locate('-', str)
给您破折号在字符串中的位置。您可以添加2
到该位置,并从该位置开始直到字符串结尾为止。最后,'1'
在字符串的开头连接。
| new_string | | :--------- | | 103950 |
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句