Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2023-08-26 08:21:02
forward
841 people have browsed it

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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!