MySQL может заменить несколько символов?

Я нашел, что этот блог был удивительным ресурсом о arcanes C++: Истины C++ .

49
задан dreftymac 15 March 2017 в 18:46
поделиться

1 ответ

You can chain REPLACE functions:

select replace(replace('hello world','world','earth'),'hello','hi')

This will print hi earth.

You can even use subqueries to replace multiple strings!

select replace(london_english,'hello','hi') as warwickshire_english
from (
    select replace('hello world','world','earth') as london_english
) sub

Or use a JOIN to replace them:

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

I'll leave translation using common table expressions as an exercise for the reader ;)

66
ответ дан 7 November 2019 в 11:46
поделиться
Другие вопросы по тегам:

Похожие вопросы: