REPLACE() Function Example
The following query replaces “World” with “w3wiki“
SELECT REPLACE("Hello World!", "World", "w3wiki") AS Greeting;
Output:
Explanation:
The given SQL query utilizes the REPLACE
function to modify the string “Hello World!” by replacing every occurrence of the substring “World” with “w3wiki“. The resulting output assigned the alias “Greeting“, is “Hello w3wiki!” – a string where the specified substitution has been applied, effectively altering the original greeting.
How to Replace Part of a String in MySQL?
To replace a part of a string in MySQL we use the REPLACE function. MySQL provides this method to manipulate string data in the tables.
In this article, we are going to see how we can update a part of the string with some other value in MySQL. Understanding this can enable string manipulation in a much more complex fashion.