oracle生成测试数据

drop table TestTable;
create table TestTable tablespace users as
select rownum as id,
to_char(sysdate + rownum/24/3600, 'yyyy-mm-dd hh24:mi:ss') as inc_datetime,
trunc(dbms_random.value(0, 100)) as random_id,
dbms_random.string('x', 20) random_string
from dual
connect by level <= 100000;

insert into TestTable
(ID, INC_DATETIME,RANDOM_ID,RANDOM_STRING)
select rownum as id,
to_char(sysdate + rownum / 24 / 3600, 'yyyy-mm-dd hh24:mi:ss') as inc_datetime,
trunc(dbms_random.value(0, 100)) as random_id,
dbms_random.string('x', 20) random_string
from dual
connect by level <= 1000000;

 

 

分批插入:

-- 创建空表
CREATE TABLE TEST_TABLE (
id NUMBER,
inc_datetime VARCHAR2(19),
random_id NUMBER,
random_string VARCHAR2(20)
) TABLESPACE users;

-- 插入数据(分批次)
BEGIN
FOR i IN 1..10 LOOP
INSERT INTO TEST_TABLE (id, inc_datetime, random_id, random_string)
SELECT rownum + (i - 1) * 200000 AS id,
TO_CHAR(SYSDATE + (rownum + (i - 1) * 200000) / 24 / 3600, 'yyyy-mm-dd hh24:mi:ss') AS inc_datetime,
TRUNC(DBMS_RANDOM.VALUE(0, 100)) AS random_id,
DBMS_RANDOM.STRING('x', 20) AS random_string
FROM dual
CONNECT BY LEVEL <= 200000;

COMMIT; -- 提交每批次的插入
END LOOP;
END;
/

posted @   zjb480  阅读(143)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示