[英]MySQL: How do I search and replace chars at the beginning of a string
I'm trying to search and replace mobile numbers with the full international code. 我正在尝试使用完整的国际代码搜索和替换手机号码。 So where rows have 07970000007 to replace the beginning with +447970000007
所以行有07970000007以+447970000007替换开头
UPDATE tblMemberImportClub
SET msisdn = REPLACE(msisdn, '07', '+447')
WHERE INSTR(msisdn, '07') = 1;
But this also replaces the other matches: 但这也取代了其他比赛:
+4479700000+447 + 4479700000 + 447
I don't think i can use TRIM as some rows will already start with +447 and will therefore nor require any updates. 我不认为我可以使用TRIM,因为某些行已经以+447开头,因此也不需要任何更新。
Thanks in advance for any assistance. 在此先感谢您的任何帮助。
SELECT
CONCAT(
REPLACE(
LEFT('07970000007',2), '07', '+447'
),
SUBSTRING('07970000007', 3, CHAR_LENGTH('07970000007'))
)as replaced
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.