MySQL REPLACE() Function
In MySQL, the REPLACE()
function replaces all occurrences of a string within another string. REPLACE()
performs a case-sensitive match.
REPLACE()
Syntax
Here is the syntax of MySQL REPLACE()
function:
REPLACE(str, search_str, replacement)
Parameters
str
- Required. The string to search and replace in.
search_str
- Required. The string to search for.
replacement
- Required. The string to replace it with.
Return value
The REPLACE(str, search_str, replacement)
function returns the string str
with all occurrences of the string search_str
replaced by the string replacement
.
The function will return NULL
if any parameter is NULL
.
REPLACE()
Examples
Here are some examples of MySQL REPLACE()
function.
SELECT
REPLACE('Hello World', 'World', 'Alice'),
REPLACE('Hello World', 'l', 'L'),
REPLACE('Hello World', 'e', 'E')\G
REPLACE('Hello World', 'World', 'Alice'): Hello Alice
REPLACE('Hello World', 'l', 'L'): HeLLo WorLd
REPLACE('Hello World', 'e', 'E'): HEllo World