本文介绍了MySQL:将REPLACE与JOIN一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在文本字段中替换多个个不同的单词.
I need to replace multiple different words in a text field.
搜索和替换值在另一个表中.
The search and replace values are in another table.
例如texts-table是:
For example the texts-table is :
The Quick Brown Fox The Dirty Red Bandana带有这样的替换表:
SearchValue ReplaceValue Quick Slow Fox Wolf Dirty Clean Bandana Hat替换后的记录将变为:
The Slow Brown Wolf The Clean Red Hat是否可以通过JOIN做到这一点?
Is it possible to do this with a JOIN?
类似的东西:
UPDATE texts_table AS tt CROSS JOIN values_table AS vt SET tt.Text= REPLACE(tt.Text, vt.SearchValue, vt.ReplaceValue)我尝试了一些不同的方法,但是无法用它来替换文本字段中的 all 字符串.
I tried some different ways, but couldn't get it to replace all strings in the text field.
推荐答案例如,您需要指定一个Join条件:
You need to specify a Join condition, for example, like this:
UPDATE texts_table AS tt INNER JOIN values_table AS vt on tt.valueId = vt.valudId /*or whatever the join condition*/ SET tt.Text= REPLACE(tt.Text, vt.SearchValue, vt.ReplaceValue)如 UPDATE 的语法中所指定条款:
As specified in the syntax of the UPDATE clause:
UPDATE [LOW_PRIORITY] [IGNORE] table_reference
table_references子句列出了联接中涉及的表. JOIN语法进行描述.
更多推荐
MySQL:将REPLACE与JOIN一起使用?
发布评论