签到天数: 2122 天 连续签到: 10 天 [LV.Master]至尊海神IIIIII
|

楼主 |
发表于 2009-8-25 20:32
|
显示全部楼层
mysql生成假MAC地址的存储过程
由于工作需要,制造很多数据库记录,想到用存储过程,其中最关键的就是生成mac,只要符合mac格式就行,下面是代码,也不是很难,用到的函数,Google一下就能搜到,现做以记录。
DELIMITER $$
DROP PROCEDURE IF EXISTS `ipcamera`.`sp_createrec`$$
CREATE DEFINER=`vcom`@`%` PROCEDURE `sp_createrec`()
label:begin
declare _firstnum int default 0;
declare _secondnum int default 0;
declare _mac char(20);
while true do
select concat('00:00:00:00:',(lpad(hex(_secondnum),2,'0')),':',(lpad(hex(_firstnum),2,'0'))) into _mac;
set _firstnum=_firstnum+1;
if(_firstnum=256) then
set _firstnum=0;
set _secondnum=_secondnum+1;
if(_secondnum=256) then
leave label;
end if;
end if;
end while;
end$$
DELIMITER ; |
|