Asked 2 years ago
31 May 2022
Views 603
eclipse-learner

eclipse-learner posted

how to use function REPLACE in MySQL?

how to use REPLACE in MySQL ? can you please explain function REPLACE in MySQL with some example?
shabi

shabi
answered Jun 2 '22 00:00

REPLACE() function can be used to find a string /character in the given string or word and replace it with the given string in MySQL.In simple words, REPLACE() function can find and replace string
REPLACE() is a string function in MySQL.
syntax :
REPLACE("main string","find string/character","replacing string/character")

for example :
REPLACE("Data is god","god","evil")
so in the above query, REPLACE() function replaces the "god" word with the "evil" word in the string "Data is god".

what REPLACE() function returns in MySQL ?
REPLACE() function return a changed string if the given string is found or returns the same main string if nothing matched.
so

REPLACE("Data is god","god","evil")//Data is evil


REPLACE("Data is god","saint","evil")//Data is god

in the above query, "saint" string is not found in "Data is god" so it returns the main string "Data is god"

is REPLACE() function case insensitive in MySQL ?
No, REPLACE() function is not case insensitive in MySQL.means it matches the string if only it has the same case type.

REPLACE("Data is god","God","evil")//Data is god

so above query , the "God" word is not matched with"god"(Lower case) so it returns the main string Data is god

Post Answer