2017-05-31 816 views
1

我有一个表名tariff,但现在我想在列service_codeMySQL的更新一个字段,替换第一个字符

替换值的数值是这样的:

D2P 
D2D 
D2D 
D2P 
D2D 

我想达到什么:

P2P 
P2D 
P2D 
P2P 
P2D 

只是改变了 'd' 到 'P',作为第一字符

+0

您的列名在服务代码空间? – lalithkumar

+0

不,错字:p ..谢谢你的回答 – may

+0

随时欢迎@ mayy – lalithkumar

回答

1

使用下面的查询:

UPDATE tariff SET service_code=CONCAT('P', SUBSTRING(service_code FROM 2)) 
    where substring(service_code,1,1)='D'; 

UPDATE tariff SET service_code=CONCAT('P', SUBSTRING(service_code FROM 2)) 
     where left(service_code,1)='D'; 
+0

不要忘记接受这个答案@may – lalithkumar

+1

我觉得你的因为她想更换为多行所有的答案是不好 – hiule

+0

是的,我明白现在该怎么办,她预计@hiule – lalithkumar

2

使用更多通用查询

update tariff set service_code='P'+substring(service_code,2,len(service_code)-1) 
where substring(service_code,1,1)='D' 
相关问题