2011-08-17 130 views
2

我有一个替代的问题MySQL中的特定字符串,但该字符串的一部分被改变,每次例如替换mysql数据库

"(my string to replace 1224:2)" 
"(my string to replace 134:4)" 
"(my string to replace 1824:9)" 
"(my string to replace 14:2)" 

我可以用这个查询

改变字符串的第一部分
update dle_post set short_story = replace(short_story,'(my','(my'); 

但是如何替换其他部分,如1224:2)14:2)或以1,2,3..)结尾的任何其他部分。我不能使用支架")",因为它在许多其他地方使用。

+0

使用正则表达式替换:http://stackoverflow.com/questions/986826/how-to-do-a -regular-expression-replace-in-mysql – DhruvPathak

+0

只有10种组合。为什么你不能把它们放在一起? – Karolis

回答

1

不是最优雅的方式,但是......

update dle_post 
set short_story = 
    replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
    short_story, 
    '0)','0)'),'1)','1)'),'2)','2)'),'3)','3)'),'4)','4)'),'5)','5)'),'6)','6)'),'7)','7)'),'8)','8)'),'9)','9)'); 
+0

好用的主意感谢 – Hafiz

+1

+ 1为坚韧不拔的打字机替换这么多次! :) – jschorr