select sys_guid() from dual ;
select dbms_random.value from dual ;
select dbms_random.value(0,100) from dual ;
select trunc(dbms_random.value(0,100)) from dual ;
select substr(cast(dbms_random.value(0,20) as varchar2(38)),0,10) from dual ;
select lpad(CHR(ROUND(dbms_random.value(47000,53000))),10,CHR(ROUND(dbms_random.value(47000,53000)))) adress from dual ;
- 正态分布的随机数
select dbms_random.normal from dual ;
- 随机字符串
select dbms_random.string('x', 3) from dual ;
/* opt可取值如下:
'u','U' : 大写字母
'l','L' : 小写字母
'a','A' : 大、小写字母
'x','X' : 数字、大写字母
'p','P' : 可打印字符*/
指定范围内随机时间日期
select to_date(TRUNC(DBMS_RANDOM.VALUE(
to_number(to_char(to_date('20150101','yyyymmdd'),'J')),
to_number(to_char(to_date('20180801','yyyymmdd')+1,'J')))),'J')+
DBMS_RANDOM.VALUE(1,3600)/3600 CREATIONDATE from dual ;
Oracle生成一百万测试数据的方法如下:
- 方法一:创建一个表,并同时添加1000000条数据,代码:
create table DataTableas
select rownum as ID,
to_char(sysdate + rownum/24/3600, 'yyyy-mm-dd hh24:mi:ss') as DOM_DATETIME,
trunc(dbms_random.value(0, 100)) as DOM_ID,
dbms_random.string('x', 20) DOM_STRING
from dual
connect by level <= 1000000;
- 方法二:在创建表后,原来表的基础上追加记录,比如在方法一创建的TestTable表中追加1000000条数据,代码:
insert into DataTable
(ID, DOM_DATETIME,DOM_ID,DOM_STRING)
select rownum as ID,
to_char(sysdate + rownum / 24 / 3600, 'yyyy-mm-dd hh24:mi:ss') as DOM_DATETIME,
trunc(dbms_random.value(0, 100)) as DOM_ID,
dbms_random.string('x', 20) DOM_STRING
from dual
connect by level <= 1000000;