开发者社区 问答 正文

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

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

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

展开
收起
保持可爱mmm 2020-05-17 12:22:13 1276 分享
分享
版权
举报
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 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论