user2373405
user2373405

Reputation: 91

Find and Replace in MySQL - Exact Match Case Only

i want to search for the exact match and replace it.

i have tried this

update [table_name]
set
    [field_name] = replace([field_name], '[string_to_find]', '[string_to_replace]');

this above query is not doing what i want. it is replacing the word, even it is in middle of another work. but i want to replace - exact match cases only.

update:

i want to replace A to APPLE and E to Elephant

when i ran 1st query it is replacing A to APPLE and then when i am running again it is replacing

E to Elephant and APPLE TO APPLELEPHANT (apple has e at the end) but i didn't want to do this

EG

CODE 

A    
E
C   

when i run this update table1 set code = replace(code, 'A', 'APPLE');

it is converting as

CODE 

APPLE    
E
C   

it is OK!

and when i ran this update table1 set code = replace(code, 'E', 'ELEPHANT');

CODE 

APPLELEPHANT    
ELEPHANT
C   

APPLE IS ALSO CONVERTING i don't want like this

Thank you!

Upvotes: 1

Views: 1304

Answers (1)

nstCactus
nstCactus

Reputation: 5183

Try this :

UPDATE [table_name] 
SET [field_name] = '[string_to_replace]'
WHERE [field_name] = [string_to_find];

Upvotes: 1

Related Questions