Name

REPLACE( )

Synopsis

REPLACE(string, old_element, new_element)

This function replaces occurrences of an element given in the second argument, that exists in the string given in first argument, with a new element given in the third.

SELECT student_id,
CONCAT(REPLACE(title, 'Mrs.', 'Ms.'),
   ' ', name_first, ' ', name_last) AS Name
FROM students;

This SQL statement will retrieve each student’s title and replace any occurrences of “Mrs.” with “Ms.,” but will leave all other titles unchanged.

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.