Compare time to populate an index by varchar2 table with one million tuples
with time to populate a database table with the same data.

drop table t;
create table t (
  idx varchar2(4000),
  data  varchar2(4000) );


procedure P is
  type text_tab_t is table of varchar2(4000) index by varchar2(4000);
  v_text_tab         text_tab_t;
  v_index            t.idx%type;
  v_data             t.data%type;

  t_start            integer;
  t_end              integer;
  c_nof_rows constant pls_integer := 1000000;

  procedure Show_Elapsed_Time ( p_start in number, p_end in number ) is
  begin
    Dbms_Output.Put_Line ( Lpad ( To_Char ( ((p_end-p_start)/100), 9999.9 ), 15 ) || ' seconds' );

  end Show_Elapsed_Time;
begin
  -- Database table ------------------------------------------------------------
  t_start := Dbms_Utility.Get_Time;
  for j in 1..c_nof_rows
  loop
    v_index := To_Char(j) || ' suffix';
    insert into t ( idx, data ) values

      ( v_index, 'data for ' || v_index );
  end loop;

  execute immediate ( 'create unique index t_idx on t ( idx )' );

  for j in ( select idx, data from t )
  loop
    v_index := j.idx; v_data := j.data;
  --Dbms_Output.Put_Line ( Rpad(v_index,20) || Rpad(v_data,20) );

  end loop;
  t_end := Dbms_Utility.Get_Time;
  Show_Elapsed_Time ( t_start, t_end );

  -- PL/SQL index by varchar2 table --------------------------------------------
  t_start := Dbms_Utility.Get_Time;
  for j in 1..c_nof_rows
  loop
    v_index := To_Char(j) || ' suffix';
    v_text_tab( v_index ) := 'data for ' || v_index;

  end loop;

  v_index := v_text_tab.First;
  while v_index is not null
  loop
  --Dbms_Output.Put_Line ( Rpad(v_index,20) || Rpad(v_text_tab(v_index),20) );
    v_index := v_text_tab.Next(v_index);
  end loop;
  t_end := Dbms_Utility.Get_Time;
  Show_Elapsed_Time ( t_start, t_end );
end P;