INSERT()
This page is part of MariaDB's Documentation.
The parent of this page is: Functions for MariaDB Xpand
Topics on this page:
Overview
Inserts a string in another string at the specified position.
USAGE
INSERT(base_string, position, length, new_string)
Argument Name | Description |
---|---|
| The string value to manipulate |
| The destination |
| The substring length that it omitted from the |
| The new string to be inserted |
DETAILS
INSERT()
is a string function that inserts the new_string
in the base_string
and returns the resulting string.
The position
argument is a 1-relative index value into the base_string
.
If the position
value is less than 1 or greater than the length of the base_string
, no change is made to the base_string
value being returned. This does mean that INSERT()
cannot concatenate the new_string
onto the end of the base_string
.
When the length
argument is non-zero, a part of the base_string
is replaced by the new_string
instead of the result being a pure insertion.
A negative length
value or a value that exceeds the length of the remaining characters in the base_string
are both interpreted to mean that the remainder of the string should be replaced.
A NULL
is returned if any argument is NULL
.
EXAMPLES
SELECT INSERT('math!', 3, -1, 'riadb') AS result1,
INSERT('math!', 3, 3, 'riadb') AS result2,
INSERT('math!', 3, 99, 'riadb') AS result3;
+---------+---------+---------+
| result1 | result2 | result3 |
+---------+---------+---------+
| mariadb | mariadb | mariadb |
+---------+---------+---------+
SELECT INSERT('math!', -1, 0, 'ignored') AS result1,
INSERT('math!', 0, 8, 'ignored') AS result2,
INSERT('math!', 6, 0, 'ignored') AS result3,
INSERT('math!', 99, 2, 'ignored') AS result4;
+---------+---------+---------+---------+
| result1 | result2 | result3 | result4 |
+---------+---------+---------+---------+
| math! | math! | math! | math! |
+---------+---------+---------+---------+
SELECT INSERT('math!', 3, 2, 'riadb') AS result;
+----------+
| result |
+----------+
| mariadb! |
+----------+