MySQL: INSERT Function

  • Post author:
  • Post category:MySQL
  • Post comments:1 Comment
MySQL INSERT Function

In this guide, we will explain how to use the MySQL INSERT function with syntax and examples.

Description

The MySQL INSERT function inserts a substring into a string at a specified position for a certain number of characters.

Syntax

The syntax for the INSERT function in MySQL is:

INSERT( string, position, number, substring )

Parameters or Arguments

string

The string to modify.positionThe position in string to insert substring.numberThe number of characters to replace in string.

substring

The substring to insert into string.

Note

  • The first position in string is 1.
  • If position is not within the length of string, the INSERT function will return string.
  • If number is not within the length of the rest of the string, the INSERT function will replace string starting from position until the end of string.

Applies To

The INSERT function can be used in the following versions of :

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

Example

Let’s look at some INSERT function examples and explore how to use the INSERT function.

For example:

mysql> SELECT INSERT('adglob.in', 1, 6, 'baldevinfo');
Result: 'baldevinfo.in'

mysql> SELECT INSERT('ad gl o b ', 9, 3, 'info');
Result: 'ad gl o b info'

mysql> SELECT INSERT('abcgh', 4, 2, 'def');
Result: 'abcdef'

mysql> SELECT INSERT('adglob.in', 99, 12, 'checkyourmath');
Result: 'adglob.in'

Next Topic : Click Here

This Post Has One Comment

Leave a Reply