Mysql replaces the last characters in a string if they match

I have a table with some rogue tags that need replacing

The breaking line ends with <tr> and needs to be replaced with </table>

Not all entries are affected, so I need to find them and then replace them.

Our skills of using the update Replacement Where are limited, because the characters are not unique in the line, but their position is, that is, the last 4 characters

Tried to use

 UPDATE table SET field REPLACE (RIGHT(field,4),</table>) 

but suspec is simplified (and also doesn't work)

+4
source share
2 answers

try the following:

 UPDATE table SET field=concat(left(field,length(field) -4),'</table>') 
+10
source

I had a similar situation in which it was necessary to replace "_" with the end of the field of transaction number, where there were more than one occurrence of _ in the field. Example: 20161124_C_BGN_5570.77_ and 20161121_C_HRK_1502360000__

Decision:

UPDATE temp SET transaction = LEFT (transaction, LENGTH (transaction) -1) WHERE RIGHT (transaction, 1) = '_';

// in case of double underscore (__)

UPDATE temp SET transaction = LEFT (transaction, LENGTH (transaction) -2) # WHERE id = xxx WHERE RIGHT (transaction, 2) = '__';

0
source

All Articles