SELECT REPLACE('Hello World', 'World', 'MySQL') AS NewString;
复制代码
结果:
NewStringHello MySQL 在这个示例中,REPLACE 函数将字符串中的 World 更换为了 MySQL。 示例 2:多个更换
如果字符串中有多个需要更换的子字符串,REPLACE 函数会对全部匹配项进行更换。例如,将字符串 apple banana apple 中的 apple 更换为 orange:
SELECT REPLACE('apple banana apple', 'apple', 'orange') AS NewString;