Introduction
The REPLACE function helps you change parts of text inside your data easily.
REPLACE(original_text, text_to_find, text_to_replace_with)
SELECT REPLACE('hello world', 'world', 'friend');
SELECT REPLACE('banana', 'a', 'o');
SELECT REPLACE('apple', 'x', 'y');
SELECT REPLACE('I love cats and cats love me', 'cats', 'dogs') AS result;
REPLACE function do in MySQL?SELECT REPLACE('hello world', 'l', 'x');SELECT REPLACE('database', 'a');products with a column code containing values like 'AB-123', 'AB-456', and 'CD-789', which query replaces the prefix 'AB-' with 'XY-' only in the code column?code values.code replacing 'AB-' with 'XY-'. SELECT REPLACE('code', 'AB-', 'XY-') AS new_code FROM products; treats 'code' as a string literal, not a column. SELECT REPLACE(code, 'XY-', 'AB-') AS new_code FROM products; reverses replacement. SELECT REPLACE(code, 'AB', 'XY') AS new_code FROM products; replaces 'AB' without the dash, which may affect unintended parts.Pass the test and this pattern moves unknown