×

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 ELT() function

In this context, we will learn how we can use the MySQL ELT() function with proper syntax and good examples. Introduction of MySQL ELT() function In the ELT function, the number field...

2 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 Command line client Basic Queries

MySQL – command line client Basic Queries There are many queries to work with the MySQL command-line client. Today, we will explore MySQL basic queries and their function. The MySQL query...

8 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 Join

The relational database system needs to interconnect multiple tables with each other. MySQL is a popular and easy data management system to connect multiple tables. The foreign key is used...

5 minutes read.

MySQL LENGTH() Function

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

2 minutes read.

MySQL CEIL() function

In this context, we will learn how we can use the MySQL CEIL () function with proper syntax and good examples. Introduction of MySQL CEIL() function Input is taken by the CEIL()...

3 minutes read.

MySQL RIGHT() Function

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

3 minutes read.

MySQL database queries

MySQL database queries Database queries help to create, use, show and, delete the database. A Database is a collection of several tables and data. The database uses SQL language to perform...

3 minutes read.

MySQL IF statement

The IF statement shows the true condition of the control flow function. The first condition is necessary to fulfill the requirement. The other condition is optional in the "IF" statement....

3 minutes read.

MySQL Clauses

MySQL Clauses MySQL system clauses are keywords or statements to handle information. It helps to operate a group of the data and apply it to require conditions. The clauses apply conditions...

16 minutes read.

MySQL Tutorial

In this tutorial, you will get information about the MySQL management system. This tutorial will cover the basic and advanced level MySQL concepts with examples that will help you become...

5 minutes read.

MySQL FIELD() function

In this context, we will learn how we can use the MySQL FIELD() function with proper syntax and good examples. Introduction of MySQL FIELD() function The index position of a mentioned value...

3 minutes read.

MySQL MONTHNAME() function

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

3 minutes read.

MySQL SEC_TO_TIME() function

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

2 minutes read.

MySQL LOG10() function

In this context, we will learn how we can use the MySQL LOG10() function with proper syntax and good examples. Introduction of MySQL LOG10() function To evaluate the natural logarithmic value of...

2 minutes read.

MySQL AVG function

This function works on numerical data type values. The average function shows the average value of the data set. If an average function returns a null value, then the row...

5 minutes read.

MySQL Advance function

The advance function operates numerical values, string values, and data types.  The advance function converts, displays, and compares given values as per requirement. Here, you find out database, table, and...

4 minutes read.

MySQL Character Length Function

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

2 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.