我有一个数据库表users,它有一个名为mobile的列。所有的手机号码都以0开头,例如:0455000000
我只想用0替换第一个数字,它总是一个61
这将把移动电话号码从0455000000转到61455000000
我猜使用trim语句可能有效,但不确定如何实现它。
发布于 2016-11-24 00:30:54
MySQL有一个名为insert()的方便函数。这允许您按位置替换子字符串。
所以:
select insert(phone, 1, 1, '') -- gets rid of the first digit
select insert(phone, 1, 1, 'Mobile #') -- replaces the first digit with a different prefix发布于 2016-11-24 00:31:31
使用substring从您的移动中删除第一个字符,然后在要替换它的开头concat值:
UPDATE users
SET mobile = concat('61', substring(mobile, 2))这是符合ANSI-SQL标准的.
发布于 2016-11-24 00:35:57
如果你想删除前0,加上61.并将其插入dB,执行以下操作:
INSERT into phone_numbers(id, number) VALUE (null, CONCAT('61', SUBSTR('0455000000', 2)))基本上它使用SUBSTR substr
https://stackoverflow.com/questions/40776321
复制相似问题