06.09.2014 Views

Laborator 5. Colectii de date PL/SQL In multe limbaje de ...

Laborator 5. Colectii de date PL/SQL In multe limbaje de ...

Laborator 5. Colectii de date PL/SQL In multe limbaje de ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Anca Ion, Proiectarea Bazelor <strong>de</strong> Date, 2010<br />

DECLARE<br />

TYPE sum_multiples IS TABLE OF <strong>PL</strong>S_INTEGER INDEX BY <strong>PL</strong>S_INTEGER;<br />

n <strong>PL</strong>S_INTEGER := 5;<br />

sn <strong>PL</strong>S_INTEGER := 10;<br />

m <strong>PL</strong>S_INTEGER := 3;<br />

BEGIN<br />

DBMS_OUTPUT.PUT_LINE('Suma primelor ' || TO_CHAR(n) || ' inmultite cu ' ||<br />

TO_CHAR(m) || ' este ' || TO_CHAR(get_sum_multiples (m, sn)));<br />

END;<br />

--creati functia<br />

FUNCTION get_sum_multiples(multiple IN <strong>PL</strong>S_INTEGER, num IN <strong>PL</strong>S_INTEGER)<br />

RETURN sum_multiples IS<br />

s sum_multiples;<br />

BEGIN<br />

FOR i IN 1..num LOOP<br />

s(i) := multiple * ((i * (i + 1)) / 2) ;<br />

END LOOP;<br />

RETURN s;<br />

END get_sum_multiples;<br />

o Atribuirea <strong>de</strong> elemente unei colectii<br />

colectie1(in<strong>de</strong>x) := colectie2;<br />

un<strong>de</strong> colectie2 este o alta colectie cu acelasi tip cu elementele ca si colectie1.<br />

Se pot folosi si operatorii pentru atribuiri <strong>de</strong> colectii: SET, MULTISET UNION,<br />

MULTISET INTERSECT si MULTISET EXCEPT.<br />

Exemplu: compatibilitate <strong>de</strong> tip la atribuirea colectiilor<br />

DECLARE<br />

TYPE last_name_typ IS VARRAY(3) OF VARCHAR2(64);<br />

TYPE surname_typ IS VARRAY(3) OF VARCHAR2(64);<br />

-- aceste 2 var au acelasi tip <strong>de</strong> data.<br />

group1 last_name_typ := last_name_typ('Jones','Wong','Marceau');<br />

group2 last_name_typ := last_name_typ('Klein','Patsos','Singh');<br />

-- a 3-a var are o <strong>de</strong>claratie asemanatoare dar n uare acelasi tip<br />

group3 surname_typ := surname_typ('Trevisi','Macleod','Marquez');<br />

BEGIN<br />

group1 := group2;<br />

--group3 := group2; -- se genereaza o eroare<br />

END;<br />

Exemplu: atribuirea tabelelor grupate folosind operatorii SET, MULTISET<br />

UNION, MULTISET INTERSECT si MULTISET EXCEPT<br />

DECLARE<br />

TYPE nested_typ IS TABLE OF NUMBER;<br />

nt1 nested_typ := nested_typ(1,2,3);<br />

nt2 nested_typ := nested_typ(3,2,1);<br />

nt3 nested_typ := nested_typ(2,3,1,3);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!