Mysql
選擇 MAC 地址並將其更新為相同格式
我有一個帶有一
macaddress
列的mysql數據庫,其中包含數千個各種格式的mac地址;大寫、小寫和帶冒號。請參閱下面的範例;+-------------------+ | macaddress | +-------------------+ | 90CCAADD3341 | +-------------------+ | 90:3f:ff:11:22:33 | +-------------------+ | 33:44:aa:bb:34:6a | +-------------------+ | 8801abcd3231 | +-------------------+
有什麼辦法可以批量更新此列中的所有行,使其格式相同?
我希望它們都是大寫的,沒有冒號,見下文;
+--------------+ | macaddress | +--------------+ | 90CCAADD3341 | +--------------+ | 903FFF112233 | +--------------+ | 3344AABB346A | +--------------+ | 8801ABCD3231 | +--------------+
我怎樣才能做到這一點?
測試選擇:
select macaddress, upper(replace(macaddress,':','')) as new_macaddress from Macs;
更新:
update macs set macaddress = upper(replace(macaddress,':',''));
測試數據:
create table macs ( macaddress varchar(20) ); insert into macs values('90CCAADD3341'); insert into macs values('90:3f:ff:11:22:33'); insert into macs values('33:44:aa:bb:34:6a'); insert into macs values('8801abcd3231');
文件連結: