Mysql Insert Function

MySQL: INSERT Function

This tutorial explains how to use the MySQL INSERT function with syntax and examples.


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


The syntax for the INSERT function in MySQL is:

INSERT( string, position, number, substring )

Parameters or Arguments


The string to modify.


The position in string to insert substring.


The number of characters to replace in string.


The substring to insert into string.


  • 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:

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


Let's look at some MySQL INSERT function examples and explore how to use the INSERT function in MySQL.

For example:

mysql> SELECT INSERT('', 1, 12, 'mysite');
Output: ''

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

mysql> SELECT INSERT('', 99, 12, 'mysite');
Output: ''