TYPE nume IS {VARRAY | VARYING ARRAY} (dimensiune) OF tip_element [NOT NULL]
TYPE nume IS TABLE OF tip_element [NOT NULL] INDEX BY BINARY_INTEGER
TYPE nume IS TABLE OF tip_element
nume_variabila nume_tip [:=valoare];
variabila:=nume_colectie([lista_de_valori)];Cu argumente la constructor se completează primele poziţii din colecţie.
set serveroutput on declare type t1 is table of char(3); type t2 is varray(10) of number; type t3 is table of number index by binary_integer; type student is record (nume varchar2(30), sectia char(10)); type t4 is table of student; c1 t1:=t1('1','2','3','4'); c2 t2:=t2(); c3 t3; studs t4:=t4(); s studenti%rowtype; i integer:=0; cursor cstudenti is select * from studenti; begin dbms_output.enable; dbms_output.put_line(to_char(c1.count)); -- da valoarea 4 c1:=t1('x'); -- se face o noua initializare pentru c1 dbms_output.put_line(to_char(c1.count)); -- da valoarea 1 dbms_output.put_line(to_char(c2.count)); -- da valoarea 0 c3(5):=5; c3(9):=9; dbms_output.put_line(to_char(c3.count)); -- da valoarea 2 dbms_output.put_line(to_char(c1.first) || '..' || to_char(c1.last)); -- da valoarea 1..1 dbms_output.put_line(to_char(c3.first) || '..' || to_char(c3.last)); -- da valoarea 5..9 --for s in (select * from studenti) loop for s in cstudenti loop studs.extend; i:=i+1; studs(i).nume:=substr(trim(s.nume) || ' ' || trim(s.prenume),30); studs(i).sectia:=s.sectia; end loop; dbms_output.put_line(to_char(studs.count)); end;
drop table temp; create table temp(Nume varchar2(50),sectia number,grupa char(13)); declare cursor cs is select nume,prenume,sectia,grupa from studenti where sectia in (1,2,3,11,22,43,44) ; type ts is table of cs%rowtype index by binary_integer; i integer; n integer:=0; n1 integer; t ts; st cs%rowtype; np varchar2(60); begin -- memorarea studentilor for st in cs loop n:=n+1; t(n):=st; end loop; --n=nr.de elemente din colectie for i in 1..n loop n1:=i+11; if n1>n then n1:=n1-n; end if; --np:=substr(trim(t(i).nume) || ' ' || t(n1).prenume || ' ', 1,50); np:=substr(trim(t(i).nume) || ' ' || t(n1).prenume || RPAD(' ',50,' '),1,50); insert into temp(nume,sectia,grupa) values(np,t(i).sectia,t(n1).grupa); end loop; end; / SELECT * FROM temp order by nume; DROP TABLE temp;