0

编辑:我想使用 mysql 查询替换特定字符之前的所有字符。特定字符的位置并不总是相同的。

选择功能给了我之前的所有字符

SELECT LEFT(description_short,LOCATE('<hr',description_short) as myresult

我如何将它与 replace 结合起来,以便我可以替换所有这些字符?

那样的东西...

UPDATE  ps_product_lang , SELECT LEFT(description_short,LOCATE('<hr ',description_short) as myresult 
SET `description_short`= replace(`description_short`,myresult,'mynewtext')

我终于明白了......我不知道这是否是优雅的方式,但它对我有用。

UPDATE my_table,(SELECT @replacetext := ((SELECT LEFT( description, LOCATE("description)-1) from my_table where my_table.id_product=72 and my_table.id_lang=4 ))) as somealias SET description= replace( description,@replacetext," mynewtextbefore characters") WHERE ( id_product='72') AND ( id_shop='1') AND ( id_lang='4')

以上查找并用“mynewtextbefore characters”替换“之前的所有字符”

4

1 回答 1

0

Probably something like that?

SELECT CONCAT('mynewtext',
              SUBSTRING(description_short, -LOCATE('<hr', description_short)-3)
       );

See http://sqlfiddle.com/#!2/69c43/3

于 2013-08-04T18:02:33.747 回答