/** 创建函数rand_number,生成随机数字 **/ DELIMITER $ CREATEFUNCTION rand_number() RETURNSINT BEGIN DECLARE i INTDEFAULT0; SET i=FLOOR(1+RAND()*100); RETURN i; END $ DELIMITER $
创建函数rand_name
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/** 创建函数rand_name,随机字符串 **/ DELIMITER $ CREATEFUNCTION rand_name(n INT) RETURNSVARCHAR(255) BEGIN DECLARE chars_str VARCHAR(100) DEFAULT'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; DECLARE return_str VARCHAR(255) DEFAULT''; DECLARE i INTDEFAULT0; WHILE i < n DO SET return_str = CONCAT(return_str,SUBSTRING(chars_str,FLOOR(1+RAND()*52),1)); SET i = i+1; END WHILE; RETURN return_str; END $ DELIMITER $
创建存储过程insert_tolove
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/** 创建存储过程insert_tolove **/ DELIMITER $ CREATEPROCEDURE insert_tolove(IN max_num INT(10)) BEGIN DECLARE i INTDEFAULT0; DECLARE EXIT HANDLER FORSQLEXCEPTIONROLLBACK; START TRANSACTION; WHILE i< max_num DO INSERTINTO test.`tolove`(ID,GIRL_NAME,GIRL_AGE,CUP_SIZE) VALUES(NULL,rand_name(5),rand_number(),NULL); SET i = i +1; END WHILE; COMMIT; END $ DELIMITER $
测试验证
1 2 3 4 5 6 7 8
/** 测试验证 **/ SETGLOBAL event_scheduler=1; COMMIT;
SELECT*FROM mysql.`event`;
SHOWFUNCTION STATUS; UPDATE mysql.`proc` SET Security_type='INVOKER';
调用存储过程insert_tolove
1 2 3
/** 调用存储过程insert_tolove **/ CALL insert_tolove(1000*10000); SELECTCOUNT(*) FROM test.`tolove` t WHERE t.girl_age='16';
/** 通过DM数据库迁移工具迁移的数据 **/ /** student 100w**/ SELECTCOUNT(*) FROM test.`student`; UPDATE test.`student` s SET s.`stu_age`='18'WHERE s.`stu_name` LIKE'A%'; UPDATE test.`student` s SET s.`stu_sex`='女';
SELECTCOUNT(*) FROM test.student t WHERE t.`stu_name` LIKE'A%'
/** test 1000w **/ SELECTCOUNT(*) FROM test.`test`;
二、Oracle生成1kw数据大表
01 使用工具plsql developer
1 2 3 4 5 6 7 8 9 10
/** Oracle11g R2 for Windows10 测试随机生成200w数据的表 **/ /** 此次测试对DM8数据库同样适用 **/ --创建表 CREATETABLE test.student ( ID NUMBER notnullprimary key, STU_NAME VARCHAR2(60) notnull, STU_AGE NUMBER(4,0) NOTNULL, STU_SEX VARCHAR2(2) notnull )