Mariadb Replace Function

MariaDB: REPLACE Function

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

Description

The MariaDB REPLACE function replaces all occurrences of a specified string.

Syntax

The syntax for the REPLACE function in MariaDB is:

REPLACE( string, from_substring, to_substring )

Parameters or Arguments

string

The source string.

from_substring

The substring to find. All occurrences of from_substring found within string are replaced with to_substring.

to_substring

The replacement substring. All occurrences of from_substring found within string are replaced with to_substring.

Note

  • The REPLACE function performs a case-sensitive replacement.

Applies To

The REPLACE function can be used in the following versions of MariaDB:

  • MariaDB 10

Example

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

For example:

SELECT REPLACE('AODBA.com', '.com', ' knows MariaDB!');
Output: 'AODBA knows MariaDB!'

SELECT REPLACE('AODBA.com', '.COM', ' knows MariaDB!');
Output: 'AODBA.com'

SELECT REPLACE('abc abc', 'b', 'X');
Output: 'aXc aXc'

SELECT REPLACE('abc abc', 'B', 'X');
Output: 'abc abc'

SELECT REPLACE('12345 12345', 1, 9);
Output: '92345 92345'