REPLACE()
String FunctionThe REPLACE()
function is used to replace all occurrences of a substring within a string.
REPLACE(str, from_str, to_str)
SELECT REPLACE('Hello World', 'World', 'MySQL');
-- Result: 'Hello MySQL'
or
SELECT REPLACE('banana', 'a', 'o');
-- Result: 'bonono'
'a'
are replaced with 'o'
.REPLACE
Statement (Table Row Upsert)MySQL also has a REPLACE INTO
statement, which is similar to INSERT
, but:
REPLACE INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);