declare
-- Local variables here
num integer;
seed number:=1000000;
a number(10);--隨機數
b number(10);--一百以內的隨機數
c number(10);--100到1000的隨機數
d number(10);--0到1的隨機數
e number(10);--1到199的隨機數
f number(10);--1到199的隨機整數
g varchar2(20);--隨機字符
h number(10);--正態分佈的隨機數
k varchar2(38);--隨機數字字符串
i date;--隨機日期
guid varchar2(38);
begin
-- Test statements here
dbms_random.initialize(seed);
dbms_output.put('seed:'||seed);
dbms_output.new_line;
/**
for i in 1..10 loop
num:=dbms_random.random()/seed;
dbms_output.put_line('num:'||num);
-- dbms_random.seed(seed);
dbms_output.put('seed:'||seed);
dbms_output.new_line;
end loop;
**/
select dbms_random.random into a from dual;--隨機數
select abs(mod(dbms_random.random,100)) into b from dual;--一百以內的隨機數
select trunc(dbms_random.value*900+100) into c from dual;--100到1000的隨機數
select dbms_random.value into d from dual;--0到1的隨機數
select dbms_random.value(1,199) into e from dual;--1到199的隨機數
select trunc(dbms_random.value(1,199)) into f from dual;--1到199的隨機整數
select dbms_random.string('p',10) into g from dual;--隨機字符--p:可打印,u:大寫,l:小寫,a:大小寫,x:數字和大寫字母
select dbms_random.normal into h from dual;--正態分佈的隨機數
select to_date(2454084+TRUNC(DBMS_RANDOM.VALUE(0,365)),'J') into i from dual;--隨機日期
select substr(cast(dbms_random.value as varchar2(38)),3,20) into k from dual;--隨機數字字符串
select sys_guid() into guid from dual;
dbms_output.put_line(a||'+'||b||'+'||c||'+'||d||'+'||e||'+'||f||'+'||g||'+'||h||'+'||i||'+'||k||'+'||guid);
dbms_random.terminate;
end;
09-26
180
