Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2326741
  • 博文数量: 473
  • 博客积分: 12252
  • 博客等级: 上将
  • 技术积分: 4307
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-12 10:02
文章分类

全部博文(473)

文章存档

2012年(8)

2011年(63)

2010年(73)

2009年(231)

2008年(98)

分类: Mysql/postgreSQL

2009-08-20 19:22:44

由于工作需要,制造很多数据库记录,想到用存储过程,其中最关键的就是生成mac,只要符合mac格式就行,下面是代码,也不是很难,用到的函数,Google一下就能搜到,现做以记录。

DELIMITER $$

DROP PROCEDURE IF EXISTS `ipcamera`.`sp_createrec`$$

CREATE
` 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 ;

阅读(2285) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~