# 存储过程-新增指定数量不重复数据
CREATE PROCEDURE `数据库名`.`存储过程名`(IN cnt INT)
BEGIN
DECLARE time INT;
DECLARE countNum INT default 1;
DECLARE code varchar(50);
SET time=cnt;
WHILE time>0 DO
set code = MD5(rand());
SELECT count(id) into countNum from 表名 where security_code = code;
if countNum <1 then
INSERT INTO 表名 (security_code) VALUES
(code);
SET time=time-1;
end if;
END WHILE ;
END
mysql 存储过程-新增指定数量不重复数据
于 2022-08-26 14:37:38 首次发布