How to insert new string within a string subsequent to removing the characters from the original string by using MySQL function?


We can use MySQL INSERT() function to insert new string within a string after removing the characters from the original string.

Syntax

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

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

@pos is the position at which the insertion of new string should start.

@len is the number of characters should delete from the original string. The starting point of deletion of characters is value of @pos.

New_string is the string we want to insert into the original string.

Example

mysql> Select INSERT('Yash Sharma',5,7,' Pal');

+----------------------------------+
| INSERT('Yash Sharma',5,7,' Pal') |
+----------------------------------+
| Yash Pal                         |
+----------------------------------+

1 row in set (0.00 sec)

Here in the above example new string ‘ Pal’ has been inserted. The insertion start from 5th character of the original string and this function remove, starting point is 5th character, total 7 characters from the original string.

Updated on: 06-Feb-2020

65 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements