问题
Here's the basic idea of what I need to do. I have two tables like the following:
Table A Table B
|id|name | |id|sentence |
|1 |hello | |1 |I like to say hello |
|2 |world | |2 |The world is large |
|3 |hello world| |3 |lorem hello ipsum world lorem ipsum hello world|
I need to cycle through the rows in Table A to look for each name in Table B. Then I want to use a REGEXP in Table B to replace the word if it is found.
For example if hello
is found in Table B it will replace the word hello
in Table B with #~Hello~#
So the fist row in table B will turn into I like to say #~Hello~#
Thanks to Gordon Linoff for a great question. So I am updating the question.
Not only can rows in Table B contain multiple words from Table A, but Table A can also have rows that contain multiple word combinations. See row 3 in Table A for reference.
In this case the longest word combination should get replaced and the shorter combination/words should be skipped. A proper working of the code would produce a Table B row 3 like the following:
lorem #~hello~# ipsum #~world~# lorem ipsum #~hello world~#
Any ideas?
来源:https://stackoverflow.com/questions/33056127/mysql-how-to-search-and-replace-data-in-one-table-a-table-with-column-from-anot