开发者社区> 问答> 正文

MySQL可以替换多个字符吗? ?mysql

我正在尝试替换MySQL字段中的一堆字符。我知道REPLACE函数,但是一次只能替换一个字符串。我在手册中看不到任何适当的功能。

我可以一次替换或删除多个字符串吗?例如,我需要用破折号替换空格并删除其他标点符号。

展开
收起
保持可爱mmm 2020-05-17 12:22:13 1193 0
1 条回答
写回答
取消 提交回答
  • 您可以链接REPLACE函数:

    select replace(replace('hello world','world','earth'),'hello','hi') 这将打印hi earth。

    您甚至可以使用子查询来替换多个字符串!

    select replace(london_english,'hello','hi') as warwickshire_english from ( select replace('hello world','world','earth') as london_english ) sub 或使用JOIN替换它们:

    select group_concat(newword separator ' ') from ( select 'hello' as oldword union all select 'world' ) orig inner join ( select 'hello' as oldword, 'hi' as newword union all select 'world', 'earth' ) trans on orig.oldword = trans.oldword 我将使用常见的表表达式来进行翻译,作为读者的练习;)来源:stack overflow

    2020-05-17 12:23:23
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
搭建电商项目架构连接MySQL 立即下载
搭建4层电商项目架构,实战连接MySQL 立即下载
PolarDB MySQL引擎重磅功能及产品能力盛大发布 立即下载

相关镜像