×

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 NATURAL JOIN

The natural join combines multiple tables using a column with the same name and data type. This operation combines a row of the two tables using common columns. This join...

4 minutes read.

MySQL DAY() function

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

2 minutes read.

MySQL Aggregate function

The aggregation function works on the multiple values and returns single value output.  It makes the advanced and complex operation simple. The summation (SUM), MAX, AVG, MIN, COUNT functions are...

5 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 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 COALESCE function

This statement displays the first non-null value of the table data. The COALESCE function returns a null value when all values of the table are null or do not find...

3 minutes read.

MySQL function

MySQL function is a piece of program to perform some specific task. Here we pass a parameter and then return a single value. MySQL function mainly supports string, numeric, conditional,...

9 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 Stored Procedure

MySQL creates the "stored procedure" function to operate database information. You can use parameters, blocks, and statements to create a new procedure. The procedure requires a database table to use...

3 minutes read.

MySQL Union

MySQL contains the same categories of data in a different table. Sometimes, you require multiple tables to collect data together. MySQL union is a function to combine two table's data...

5 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 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 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 REVERSE() function

In this context, we will learn how we can use the MySQL REVERSE() function with proper syntax and good examples. Introduction of MySQL REVERSE() function This function could be used to reverse...

2 minutes read.

MySQL Triggers

MySQL trigger is a function of the stored procedure to respond to the system program. This function responds and runs any data table event automatically. You can use it for...

5 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 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: 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.

MySQL NOW() function

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

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.