Knowledge Base   /   MYSQL

MySQL REPLACE() function

Posted on 18 January 2023 01:43 pm

MySQL REPLACE() replaces all the occurrences of a substring within a string.

_______________________________________

SELECT * FROM schema.table;
UPDATE schema.table set column= replace(column, 'aaa', 'AAA') WHERE column='aaa';

_______________________________________

schema = is the chema db (e.g. company)

table = is the name of the table (e.g. users)

column = is the column name of the table (e.g. description)

aaa = is the string which will be replaced in the column

AAA = is the string who replace the "aaa"

 

reference: https://www.w3resource.com/mysql/string-functions/mysql-replace-function.php