User Tools

Site Tools


kurs:table_index_by_varchar2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
kurs:table_index_by_varchar2 [2011/11/16 12:52]
mh
kurs:table_index_by_varchar2 [2015/04/16 09:28]
mh
Line 68: Line 68:
  
 END; -- Procedure END; -- Procedure
 +</​code>​
 +
 +<​code>​
 +CREATE OR REPLACE PROCEDURE DEMO_HASH AS 
 +
 +type person_record is record (
 +   ​r_name varchar2(100),​
 +   ​r_height integer);
 +   
 +type simple_person_table_type is table of person_record
 +  index by binary_integer;​
 +
 +type person_table_type is table of persons%rowtype
 +  index by varchar2(20);​
 +
 +type person_table_i_type is table of persons%rowtype
 +  index by binary_integer;​
 +
 +cursor c_persons is (select * from persons);
 +
 +tn simple_person_table_type;​
 +
 +v_per person_table_type;​
 +v_i_per person_table_i_type;​
 +
 +v_i binary_integer;​
 +v_vc varchar2(100);​
 +BEGIN  ​
 +
 +tn(10).r_name := '​Mark';​
 +tn(10).r_height := 175;
 +
 +tn(2000).r_name := '​Michael';​
 +tn(2000).r_height := 183;
 +
 +v_i := tn.first;
 +while v_i is not null loop 
 +  dbms_output.put_line(v_i || ' ' ||tn(v_i).r_name);​
 +  v_i := tn.next(v_i);​
 +end loop;
 +
 +v_per('​Michael'​).per_name := '​Michael';​
 +v_per('​Michael'​).per_birthday := to_date('​1981-04-25',​ '​yyyy-mm-dd'​);​
 +
 +for r in (select * from persons) loop 
 +  v_per(r.per_name) := r;
 +end loop;  ​
 +
 +open c_persons;
 +fetch c_persons bulk collect into v_i_per;
 +close c_persons;
 +
 +dbms_output.put_line('​bulk collect result'​);​
 +for i in 1 .. v_i_per.last loop 
 +dbms_output.put_line(v_i_per(i).per_name||'​ '||
 +                     ​v_i_per(i).per_birthday ​                      
 +                    );
 +end loop;                    ​
 +dbms_output.put_line('​***'​);​
 +
 +
 +
 +v_vc := v_per.first;​
 +while v_vc is not null loop 
 +  dbms_output.put_line(v_vc || ' ' ||v_per(v_vc).per_name||'​ '||
 +                       ​v_per(v_vc).per_birthday ​                      
 +                       );
 +                       
 +  if v_per(v_vc).per_education is not null then                      ​
 +    dbms_output.put_line(
 +    v_per(v_vc).per_education(v_per(v_vc).per_education.last)
 +    );
 +  end if;
 +  v_vc := v_per.next(v_vc);​
 +end loop;
 +
 +
 +END DEMO_HASH;
 </​code>​ </​code>​
kurs/table_index_by_varchar2.txt ยท Last modified: 2015/04/16 09:28 by mh