INSERT()

Overview

Inserts a string in another string at the specified position.

USAGE

INSERT(base_string, position, length, new_string)

Argument Name

Description

base_string

The string value to manipulate

position

The destination position in the base_string where the new_string is inserted

length

The substring length that it omitted from the base_string at the destination position

new_string

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.

SYNONYMS

SCHEMA

PARAMETERS

SKYSQL

PRIVILEGES

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! |
+----------+

ERROR HANDLING

FEATURE INTERACTION

RESPONSES

DIAGNOSIS

ISO 9075:2016

CHANGE HISTORY

Release Series

History

23.09

  • Present starting in MariaDB Xpand 23.09.1.

6.1

  • Present starting in MariaDB Xpand 6.1.0.

6.0

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.

Release Series

History

6.0

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.

Release Series

History

6.1

  • Present starting in MariaDB Xpand 6.1.0.

EXTERNAL REFERENCES