开发者

Update MySQL using a regular expression

开发者 https://www.devze.com 2023-02-20 13:18 出处:网络
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.

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 resul开发者_运维问答t 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.


What about something like this, using the REGEX operator :

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

精彩评论

暂无评论...
验证码 换一张
取 消