Basel Ahmed
Basel Ahmed

Reputation: 19

replace text within parentheses with string in table column using set regexp_replace (MySQL)

I'm trying to replace the text within parentheses and the parentheses with string in table column using set regexp_replace

e.g. "Apartment (H B)" to be "Rental"

I have tried the following but did not work any idea what to do?

UPDATE prime_location
    SET Type = 
        regexp_replace(regexp_replace(regexp_replace(Type,')',' '),
                '(',' '), 'Apartment H B ', 'Rental')
WHERE Type IN ('(',')','Apartment H B');

I need to use the set regexp_replace

Thanks

Upvotes: 0

Views: 118

Answers (1)

RiggsFolly
RiggsFolly

Reputation: 94682

A simpler solution using the REPLACE() function

UPDATE prime_location
    SET Type = REPLACE(Type, "Apartment (H B)", "Rental")

Upvotes: 2

Related Questions