select inet_ntoa(ip_address) as myip,mymac
from table1
解决方法:
假设您通过抑制所有分隔符并将生成的hex数转换为int来存储mac地址,则从此int到人类可读mac地址的转换将是:
function int2macaddress($int) {
$hex = base_convert($int, 10, 16);
while (strlen($hex) < 12)
$hex = '0'.$hex;
return strtoupper(implode(':', str_split($hex,2)));
}
该功能取自http://www.onurguzel.com/storing-mac-address-in-a-mysql-database/
这个函数的mysql版本:
delimiter $$
create function itomac (i bigint)
returns char(20)
language sql
begin
declare temp char(20);
set temp = lpad (hex (i), 12, '0');
return concat (left (temp, 2),':',mid(temp,3,2),':',mid(temp,5,2),':',mid(temp,7,2),':',mid(temp,9,2),':',mid(temp,11,2));
end;
$$
delimiter ;
您也可以直接在sql中执行此操作,如下所示:
select
concat (left (b.mh, 2),':',mid(b.mh,3,2),':',mid(b.mh,5,2),':',mid(b.mh,7,2),':',mid(b.mh,9,2),':',mid(b.mh,11,2))
from (
select lpad (hex (a.mac_as_int), 12, '0') as mh
from (
select 1234567890 as mac_as_int
) a
) b
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!