Insert random numbers into a table : DBMS_RANDOM « System Packages « Oracle PL / SQL






Insert random numbers into a table

   
SQL>
SQL> create table t( c1 int, c2 int, c3 int, c4 int ) storage ( freelists 10 );

Table created.

SQL>
SQL>
SQL> set echo on
SQL>
SQL>
SQL>      declare
  2           myNumber number;
  3       begin
  4           for i in 1 .. 10
  5           loop
  6               myNumber := dbms_random.random;
  7               insert into t values( myNumber, myNumber, myNumber, myNumber );
  8           end loop;
  9           commit;
 10       end;
 11  /

PL/SQL procedure successfully completed.

SQL>
SQL> select * from t;
        C1         C2         C3         C4
---------- ---------- ---------- ----------
-1.731E+09 -1.731E+09 -1.731E+09 -1.731E+09
-1.831E+09 -1.831E+09 -1.831E+09 -1.831E+09
1272757711 1272757711 1272757711 1272757711
 291563057  291563057  291563057  291563057
1906157085 1906157085 1906157085 1906157085
 180671850  180671850  180671850  180671850
1011541972 1011541972 1011541972 1011541972
-1.686E+09 -1.686E+09 -1.686E+09 -1.686E+09
-863840673 -863840673 -863840673 -863840673
1602415758 1602415758 1602415758 1602415758

10 rows selected.

SQL>
SQL> drop table t;

Table dropped.

SQL> --

   
    
  








Related examples in the same category

1.ROUND a DBMS_RANDOM.VALUE
2.This script illustrates the use of the DBMS_RANDOM package.
3.Call dbms_random.normal to get a random number
4.Use dbms_random.string to create random string
5.dbms_random.value
6.Random string with dbms_random.string
7.Seed a random value with dbms_random.seed
8.Round a random value from dbms_random.value
9.trunc a random value from dbms_random.value
10.mod(abs(dbms_random.random),50000)+1
11.Insert random value to table