Oracle DBMS_RANDOM Package to Generate Random Numbers, Strings

Generate random decimal value
SQL> select dbms_random.value from dual;

     VALUE
----------
.969676006
Generate a random number between 1 and 1000


SQL> select trunc(dbms_random.value(1,1000)) from dual;

TRUNC(DBMS_RANDOM.VALUE(1,1000))
--------------------------------
                             231

Generate random number between 1 and 3

SQL> select trunc(dbms_random.value(1,3)) from dual;

TRUNC(DBMS_RANDOM.VALUE(1,3))
-----------------------------
                            1

SQL> select trunc(dbms_random.value(1,3)) from dual;

TRUNC(DBMS_RANDOM.VALUE(1,3))
-----------------------------
                            2
Generate Random string of length 5 and mixed case. First argument should be either A or a

SQL> SELECT DBMS_RANDOM.STRING('A', 5) ran_str from dual;

RAN_STR
----------
hXLQi

Generate Random string of length 5 and Lower case. First argument should be either L or l

SQL> SELECT DBMS_RANDOM.STRING('L', 5) ran_str from dual;

RAN_STR
----------
sxifw

Generate Random string of length 5 and Upper case. First argument should be either U or u

SQL>  SELECT DBMS_RANDOM.STRING('U', 5) ran_str from dual;

RAN_STR
----------
QKPHC
DBA Tips Data Pump Reference

0 comments:

Post a Comment

 

dba topics. Copyright 2011-16 All Rights Reserved | Site Map | Contact | Disclaimer | Google