SQL REPLACE() string replacement function
May 16, 2021
SQL
Table of contents
SQL REPLACE() string replacement function
Instance
Replace the
w3cschool string in all
the title fields in the database table article with hello.
update `article` set title=replace(title,'w3cschool','hello');
The replace function definition
replace(original-string,search-string,replace-string)
Parameters
-
original-string: The string being searched. C
an be any length.
-
search-string: A string to search for and replace-string. T
he string should not be longer than 255 bytes. I
f search-string is an empty string, the original string is returned as is.
-
replace-string: This string is used to replace search-string. C
an be any length. I
f replace-string is an empty string, delete all search-strings that appear.
Description
Replace string expression 3 with a match for all string expression 2 that appears in string expression 1. R
eturns a new string.
If there is an argument that is NULL, this function returns NULL.