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

时间:2023-01-27 13:17:27

Edit: i would like to replace all characters, before a specific character , using mysql query. The location of the specific character is not always the same.

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

The select function is giving me all the characters before

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

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

How i can combine it with the replace , so i can replace all those characters?

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

Something like that...

这样的东西......

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

I got it finally... i dont know if it is the elegant way , but it works for me.

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

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')

UPDATE my_table,(SELECT @replacetext:=((SELECT LEFT(description,LOCATE(“description)-1)from my_table,其中my_table.id_product = 72和my_table.id_lang = 4)))作为somealias SET description = replace(description, @replacetext,“mynewtextbefore characters”)WHERE(id_product = '72')AND(id_shop ='1')AND(id_lang ='4')

The above find and replace with "mynewtextbefore characters" all the characters before "

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

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

#1


0  

Probably something like that?

可能是这样的?

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

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