Mysql Replace Function

MySQL: REPLACE Function

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

Description

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

Syntax

The syntax for the REPLACE function in MySQL 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 MySQL:

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

Example

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

For example:

mysql> SELECT REPLACE('AODBA.com', 'AODBA', 'mysite');
Output: 'mysite.com'

mysql> SELECT REPLACE('AODBA.com', 'AODBA', 'mysite');
Output: 'AODBA.com'

mysql> SELECT REPLACE('abc abc', 'a', 'B');
Output: 'Bbc Bbc'

mysql> SELECT REPLACE('abc abc', 'A', 'B');
Output: 'abc abc'

mysql> SELECT REPLACE('123 123', 2, 5);
Output: '153 153'