Insert substring into a string at a specific index from the end. How to mysql?


I have problem with mysql insert().

I have strings of variable length (15-20 chars) in a table, and I need to add 4 characters to every string. The catch is that I need to add them exactly 4 chars before the end of the string.

For example, given input string 1234567890-123 I need to add 'ABCD' before '-', so that the string becomes 1234567890ABCD-123.

  • I tried with insert() function but it can't do it.
  • Is there solution for this or do I need to write an application to do it?
  • I use MySQL 4.1.

REPLACE provide a solution:

UPDATE `table` SET `column` = REPLACE(`column`, '-', 'ABCD-');