如何使用MySQL删除两个固定字符串之间的随机字符串?

时间:2015-04-18 22:59:36

标签: mysql sql string preg-replace

以下是我的MySQL数据库中的一些短语:

I love swimming and writing.
I love shopping and writing.
I love playing games and writing.

如何将其更改为

I love writing.
I love writing.
I love writing.

1 个答案:

答案 0 :(得分:0)

不要将其视为删除中间的字符串,就像将常量字符串设置为与模式匹配的任何内容一样:

UPDATE my_table
SET    my_column = 'I love writing.'
WHERE  my_column LIKE 'I love% writing.'