Random value based on sequence : Sequence Value « Sequence « Oracle PL / SQL






Random value based on sequence

 

SQL> create table emp (id number(6) );

Table created.

SQL>
SQL> alter table emp modify id number(12);

Table altered.

SQL>
SQL> create sequence cust_seq cache 1000
  2  start with 100000;

Sequence created.

SQL>
SQL> create or replace procedure gen_emp is
  2   v_new_cid emp.id%type;
  3  begin
  4   insert into emp values (cust_seq.nextval*100000+ round(dbms_random.value(100000,999999)));
  5  end;
  6  /

Procedure created.

SQL>
SQL> begin
  2      for i in 1 .. 10000 loop
  3          gen_emp;
  4      end loop;
  5      commit;
  6  end;
  7  /

PL/SQL procedure successfully completed.

SQL>
SQL>
SQL> drop sequence cust_seq;

Sequence dropped.

SQL>
SQL>
SQL> drop table emp;

Table dropped.

   
  








Related examples in the same category

1.Use sequence in insert command
2.Sequence current value and next value
3.Get Sequence next value
4.Sequence max value: 999999999999999999999999999
5.Set sequence max value
6.Use Sequence in a procedure
7.If new value is null use the value from a sequence
8.Automatically including unique sequence numbers during an INSERT.