In MySQL, how can we insert a substring at the specified position in a string?

We can use a MySQL INSERT() function to insert a substring at the specified position in a string.


INSERT(original_string, @pos, @len, new_string)

Here, original_string is the string in which we want to insert a new string at the place of some specific number of characters.

  • @pos is the position at which the insertion of the new string should start.
  • @len is the number of characters that should delete from the original string. The starting point of the deletion of characters is the value of @pos.
  • New_string is the string we want to insert into the original string.


mysql> Select INSERT('MySQL Tutorial',7,8,'@Tutorialspoint');
| INSERT('MySQL Tutorial',7,8,'@Tutorialspoint') |
| MySQL @Tutorialspoint                          |
1 row in set (0.00 sec)

Here in the above example new string ‘@Tutorialspoint’ has been inserted. The insertion start from the 7th character of the original string and this function removes, the starting point is a 7th character, total of 8 characters from the original string.

Updated on: 22-Jun-2020


Kickstart Your Career

Get certified by completing the course

Get Started