×

MySQL INSERT() Function

In this context, we will learn how we can use the MySQL INSERT() function with proper syntax and good examples.

Introduction of MySQL INSERT() function

Basically, in MySQL, the INSERT function is used for adding a string within a string and removing a number of characters from the main string.

Syntax of the MySQL INSERT() function

The syntax of the MySQL INSERT() function is given as follows:

INSERT(str, pos, len, newstr)

Parameters or arguments used in MySQL INSERT() function:

There are four parameters accepted by the INSERT() function in MySQL, which are mentioned below:

Str- It is the main string in which we want to add another string.

Pos – It is the position where we want to add another string.

Len – The number of characters to replace.

newstr – The string to be inserted.

Returns:

It will return a newly formed string.

Application used for INSERT() function:

The INSERT() function can be used in the given below MySQL versions.:

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

Examples of MySQL INSERT() function:

Now we will look into some MySQL INSERT() function examples and will explore how we can use the INSERT function in MySQL.

Example-1 :

Here, we will insert the string "MySQL" into the string "javatpoint" and replace five characters, starting from position 6 with the help of the INSERT Function.

SELECT INSERT("javatpoint," 6, 5, "MySQL")
AS NewString ;

Output:

NEWSTRING
javatmysql
1 row in set (0.00 sec)

Example-2 :

The following MySQL statement returns the Original string, the actual string itself. This happens because the position of insertion, which is specified as -5, is out of range, so no insertion takes place.

SELECT INSERT("javatpoint," -5, 5, "MySQL")

SELECT INSERT("javatpoint," -5, 5, "MySQL")
AS NewString ;

Output:

NEWSTRING
geeksforgeeks
1 row in set (0.00 sec)

Example-3 :

The following MySQL statement returns a completely new string. This happens because the insertion position is 1, and length is the number of characters in the previous string.

SELECT INSERT("javatpoint," 1, 13, "StackOverflow")
AS NewString ;

Output:

NEWSTRING
Stackoverflow
1 row in set (0.00 sec)

Application of MySQL INSERT() function:

This function is used for adding a string within a string and removing a number of characters from the main string.

Summary:

In the above context, we have learned how we can use the INSERT() function in MySQL used for adding a string within a string and removing a number of characters from the main string.


Related Topics

MySQL Math Function

The math function operates numerical values and displays required number data. The math function finds out sin, cos, tan values. Here, you find out the absolute value, reminder, and logarithmic...

6 minutes read.

MySQL vs Oracle

What is MySQL? The open-source MySQL relational database management system is a vital software component for web-based applications. As the data is saved and sent over the internet, databases and related...

6 minutes read.

MySQL CROSS JOIN

MySQL CROSS JOIN combines all possibilities of the two or more tables and returns the result that contains every row from all contributing tables. It links several columns from the...

4 minutes read.

MySQL Drop Index

Sometimes we have an index that is not required in data operations. In that case, we can use this statement to remove an existing index from the table. We can...

4 minutes read.

MySQL POW() function

In this context, we will learn how we can use the MySQL POW() function with proper syntax and good examples. Introduction of MySQL POW() function This function in MySQL is used to...

2 minutes read.

MySQL Advance table Query

MySQL Advance table Query The table is created by index, rows, and columns in the MySQL database. The user saves their information in matrix format. The database requires a query to...

14 minutes read.

MySQL RTRIM() function

In this context, we will learn how we can use the MySQL RTRIM() function with proper syntax and good examples. Introduction of MySQL RTRIM() function It is the function in MySQL that...

2 minutes read.

MySQL FIND_IN_SET() function

In this context, we will learn how we can use the MySQL MOD() function with proper syntax and good examples. Introduction of MySQL MOD() function MySQL provides a built-in string function called...

4 minutes read.

MySQL FLOOR() function

In this context, we will learn how we can use the MySQL FLOOR() function with proper syntaxes and examples. Introduction of MySQL Floor() function: FLOOR() function in MySQL is used to return...

3 minutes read.

MySQL Control flow function

The control flow function uses values or operands for logical operations. These functions can works on single and multiple conditions. The control flow function is based on the Boolean expression....

3 minutes read.

MySQL SOUNDEX() function

In this context, we will learn how we can use the MySQL SOUNDEX() function with proper syntax and good examples. Introduction of MySQL SOUNDEX() function SOUNDEX() function in MySQL is used to...

3 minutes read.

MySQL Invisible Index

Invisible Index MySQL index decides an option to the availability of the index for the query optimizer. This index shows the visible and invisible options to displays the index column in...

3 minutes read.

MySQL logical conditions

MySQL logical conditions Introduction MySQL handles data with clauses, operators, and conditions. The logical condition is used to compare information and returns the required output. This condition applies logic to MySQL expressions...

7 minutes read.

MySQL LEAST function

This statement displays the smallest value of the table. The LEAST function returns a null value when the table contains a null value. If the table contains all numerical values,...

2 minutes read.

MySQL View

Introduction MySQL View is a virtual table to create a clone of the base table. The View does not contain its values or data. MySQL View creates to connect more than...

12 minutes read.

MySQL PERIOD_DIFF() function

In this context, we will learn how we can use the MySQL PERIOD_DIFF() function with proper syntax and good examples. Introduction of MySQL PERIOD_DIFF() function This function in MySQL is used to...

2 minutes read.

MySQL COUNT function

The count function returns the number of rows in the table. This function shows either the entire rows count or the required row count of the table. It determines the...

5 minutes read.

MySQL LOAD_FILE() function

In this context, we will learn how we can use the MySQL LOAD_FILE() function with proper syntax and good examples. Introduction of MySQL LOAD_FILE() function The LOAD_FILE() function in MySQL reads a...

3 minutes read.

MySQL Table Query

MySQL table query A database stored a lot of data and divided them into different relations known as tables. Each database can contain more than one table. These tables are created...

7 minutes read.

MySQL: Entity-Relationship Model

Entity-Relationship Model Entity-Relationship model or E R model is used to create a relationship between different attributes or entities. It describes the structure of the database with the help of the...

5 minutes read.