This tutorial explains how to use the MySQL REPLACE function with syntax and examples.
The MySQL REPLACE function replaces all occurrences of a specified string.
The syntax for the REPLACE function in MySQL is:
REPLACE( string, from_substring, to_substring )
The source string.
The substring to find. All occurrences of from_substring found within string are replaced with to_substring.
The replacement substring. All occurrences of from_substring found within string are replaced with to_substring.
The REPLACE function can be used in the following versions of MySQL:
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'