totn MariaDB Functions

MariaDB: INSERT Function

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

Description

The MariaDB 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 MariaDB is:

INSERT( string, position, number, substring )

Parameters or Arguments

string
The string to modify.
position
The position in string to insert substring.
number
The 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 MariaDB:

  • MariaDB 10

Example

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

For example:

SELECT INSERT('CheckYourMath.com', 1, 13, 'TechOnTheNet');
Result: 'TechOnTheNet.com'

SELECT INSERT('Tech on the Net', 13, 3, 'Internet');
Result: 'Tech on the Internet'

SELECT INSERT('aXYZh', 2, 3, 'bcdefg');
Result: 'abcdefgh'

SELECT INSERT('TechOnTheNet.com', 99, 1, 'Z');
Result: 'TechOnTheNet.com'