mysql 替换字符第一次_mysql – SQL:搜索/替换但只是第一次出现...

这实际上应该是你想要的MySQL:

UPDATE wp_post

SET post_content = CONCAT(REPLACE(LEFT(post_content, INSTR(post_content, 'A')), 'A', 'B'), SUBSTRING(post_content, INSTR(post_content, 'A') + 1));

它比我之前的答案稍微复杂一点 – 你需要找到’A’的第一个实例(使用INSTR函数),然后使用LEFT结合REPLACE来替换那个实例,而不是使用SUBSTRING和INSTR来找到它’A’你正在用前一个字符串替换和CONCAT它.

请参阅下面的测试:

SET @string = 'this is A string with A replace and An Answer';

SELECT @string as actual_string

, CONCAT(REPLACE(LEFT(@string, INSTR(@string, 'A')), 'A', 'B'), SUBSTRING(@string, INSTR(@string, 'A') + 1)) as new_string;

生产:

actual_string new_string

--------------------------------------------- ---------------------------------------------

this is A string with A replace and An Answer this is B string with A replace and An Answer

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值