Home >Database >Mysql Tutorial >In MySQL, how to insert a substring at a specified position in a string?

In MySQL, how to insert a substring at a specified position in a string?

WBOY
WBOYforward
2023-08-26 08:21:02962browse

In MySQL, how to insert a substring at a specified position in a string?

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

Syntax

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

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

  • @pos is the position where the new string is to be inserted. Insertion of new strings should begin.
  • @len is the number of characters that should be removed from the original string. The starting point for deleting characters is the value of @pos.
  • New_string is the string we want to insert into the original string.

Example

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

In the above example, the new string "@Tutorialspoint" has been inserted. Insertion starts at character 7 of the original string, and this function deletes starting point at character 7, for a total of 8 characters in the original string.

The above is the detailed content of In MySQL, how to insert a substring at a specified position in a string?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete