jamjam
jamjam

Reputation: 379

Update MySQL using a regular expression

I have a table called location with a field area. This field can contain various types of values.

Example: London, New York, Tokoyo, 3, 10, 99, 149, 2743, etc.

Using a regular expression I want to update this field if it containes a 1 or 2 digit number by adding the word Area. So using the example above, the update will result in Area 3, Area 10, Area 99.

The rest of the values will be ignored as they don't meet the criteria. Hopefully that makes sence.

Upvotes: 2

Views: 826

Answers (1)

Pascal MARTIN
Pascal MARTIN

Reputation: 400972

What about something like this, using the REGEX operator :

UPDATE  location
SET     area = concat('Area ', area)
WHERE   area REGEXP '^[0-9]{1,2}$'

Upvotes: 2

Related Questions