分类:笔记 日期:2020-08-10 作者:caocaofff 浏览:1100
我的环境:10.4.12-MariaDB
需要批量往某个表插入大量随机数据,其中一个字段是MAC地址,由于格式特殊,所以需要一个存储过程去调用
CREATE DEFINER=`root`@`%` FUNCTION `getMac`()
RETURNS varchar(50) CHARSET utf8
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN
DECLARE str varchar(50);
DECLARE mac varchar(50);
SET str='0123456789ABCDE';
SET mac = SUBSTRING(str,FLOOR(1 + RAND() * 14),1);
SET mac = CONCAT(mac, SUBSTRING(str,FLOOR(1 + RAND() * 14),1),':');
SET mac = CONCAT(mac, SUBSTRING(str,FLOOR(1 + RAND() * 14),1));
SET mac = CONCAT(mac, SUBSTRING(str,FLOOR(1 + RAND() * 14),1),':');
SET mac = CONCAT(mac, SUBSTRING(str,FLOOR(1 + RAND() * 14),1));
SET mac = CONCAT(mac, SUBSTRING(str,FLOOR(1 + RAND() * 14),1),':');
SET mac = CONCAT(mac, SUBSTRING(str,FLOOR(1 + RAND() * 14),1));
SET mac = CONCAT(mac, SUBSTRING(str,FLOOR(1 + RAND() * 14),1),':');
SET mac = CONCAT(mac, SUBSTRING(str,FLOOR(1 + RAND() * 14),1));
SET mac = CONCAT(mac, SUBSTRING(str,FLOOR(1 + RAND() * 14),1),':');
SET mac = CONCAT(mac, SUBSTRING(str,FLOOR(1 + RAND() * 14),1));
SET mac = CONCAT(mac, SUBSTRING(str,FLOOR(1 + RAND() * 14),1));
RETURN mac;
END
CC版权: 本篇博文采用《CC 协议》,转载必须注明作者和本文链接