declare
  id VARCHAR2(40);
  firstname VARCHAR2(20);
  lastname VARCHAR2(20);
  name VARCHAR2(50);
  birthdate DATE;
  zip VARCHAR2(5);
  i NUMBER;
  rand1 NUMBER;
  rand2 NUMBER;
  rand3 NUMBER;
  max_id_firstname NUMBER;
  max_id_lastname NUMBER;
  max_id_city NUMBER;
begin
  select max(id) into max_id_firstname from US_FIRSTNAME;
  select max(id) into max_id_lastname  from US_LASTNAME;
  select max(id) into max_id_city  from CITY;
  
  for i in 1..1000000 loop
    rand1:=round(dbms_random.value(1,max_id_firstname));
    rand2:=round(dbms_random.value(1,max_id_lastname));
    rand3:=round(dbms_random.value(1,max_id_city));
    SELECT FIRSTNAME into firstname FROM US_FIRSTNAME where ID=rand1;
    SELECT LASTNAME into lastname FROM US_LASTNAME where ID=rand2;
    SELECT ZIP into zip FROM CITY where ID=rand3;
    
    NAME:=FIRSTNAME ||' '|| LASTNAME;

    SELECT TO_DATE(
              TRUNC(
                   DBMS_RANDOM.VALUE(TO_CHAR(DATE '1960-01-01','J')
                                    ,TO_CHAR(DATE '2011-12-31','J')
                                    )
                    ),'J'
               ) into birthdate FROM DUAL;

    insert into CLIENT(ID,NAME,BIRTHDATE,ZIP) values (i,NAME,BIRTHDATE,ZIP);
    if mod(i,10000)=0 then
      commit;
    end if;
    end loop;
  commit;
end;
/

