在特定字符,mysql查询之前替换所有字符

时间:2013-08-04 17:48:51

标签: mysql replace

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

select函数给我之前的所有字符

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

我如何将它与替换组合,所以我可以替换所有这些角色?

像这样......

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

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

更新my_table,(SELECT @replacetext:=((SELECT LEFT(description,LOCATE(“description)-1)来自my_table,其中my_table.id_product = 72,my_table.id_lang = 4) ))作为somealias SET description =替换(description,@ replacetext,“mynewtextbefore characters”) WHERE(id_product ='72') AND(id_shop ='1') AND(id_lang ='4')

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

1 个答案:

答案 0 :(得分:0)

可能是这样的吗?

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

请参阅http://sqlfiddle.com/#!2/69c43/3

相关问题