user1589800 user1589800 - 1 year ago 127
MySQL Question

mysql replace last characters in string if matched

I have a table that has some rogue tags that need replacing

The offending string ends

<tr>
and needs replacing with
</table>


Not all record are affected, so I need to find these and then replace them

Our skills using Update Replace Where are limited as the characters are not unique within the string but their position is, ie the last 4 characters

Have tried using

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


but suspec this is over simplified (and also fails)

Answer Source

try this:

UPDATE table
SET field=concat(left(field,length(field) -4),'</table>')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download