MySQL:将REPLACE与JOIN一起使用?

编程入门 行业动态 更新时间:2024-10-24 14:23:07
本文介绍了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一起使用?

本文发布于:2023-07-09 02:24:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1082883.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:MySQL   REPLACE   JOIN

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!