Open In App

REPLACE() Function in MySQL

Last Updated : 31 Aug, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

REPLACE() function could be used to replaces all presence of a substring within a string, with a new substring. REPLACE() function is a case-sensitive.

Syntax :

SELECT REPLACE(string, from_string, new_string)

Parameter string is used to replace the original string from_string to be new_string.

Example-1:
In this example, you will see how you can replace any string value with a new string value by using the replace function.
Let’s consider an example where “MySQL” replace with “HTML” value. Below given is the replace function values.

Replace "MySQL" with "HTML"

Now, you will see how you can read the replace values.

SELECT REPLACE("MySQL in Geeksforgeeks", "SQL", "HTML");

Output :

REPLACE(“MySQL in Geeksforgeeks”, “MySQL”, “HTML”)
HTML in Geeksforgeeks

Example-2:

Replace "X" with "A"

Now, If you want to read the replaced value then use the following function given below.

SELECT REPLACE("It is Good to study XXX from GFG", "X", "A");

Output :

REPLACE(“It is Good to study XXX from GFG”, “X”, “A”)
It is Good to study AAA from GFG

Example-3:

Replace "x" with "a"

Now, If you want to read the replaced value then use the following function given below.

SELECT REPLACE("It is Good to study xxx from GFG", "x", "a");

Output :

REPLACE(“It is Good to study xxx from GFG”, “x”, “a”)
It is Good to study aaa from GFG

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads