一、编写存储过程
DELIMITER $$
CREATE PROCEDURE insett_dept(IN START INT(10), IN max_num INT(10))
BEGIN
DECLARE i INT DEFAULT 0;
SET autocommit = 0;
REPEAT
SET i = i + 1;
INSERT INTO t_dept(deptno, dname, loc) VALUES((START + i), getRandString(10), getRandString(5));
UNTIL i = max_num
END REPEAT;
COMMIT;
END $$
DELIMITER $$
CREATE PROCEDURE insert_emp(IN START INT(10), IN max_num INT(10))
BEGIN
DECLARE i INT DEFAULT 0;
SET autocommit = 0;
REPEAT
SET i = i + 1;
INSERT INTO t_emp(empno, ename, deptno) VALUES((START + i), getRandString(6), randNum());
UNTIL i = max_num
END REPEAT;
COMMIT;
END $$
二、调用存储过程
CALL insett_dept(100, 10)
网友评论