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 ...
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 />
ELSE<br />
DBMS_OUTPUT.PUT_LINE('<strong>In</strong>ainte <strong>de</strong> initializare, vectorul nu este nul.');<br />
END IF;<br />
<strong>de</strong>pt_names := dnames_var(); -- initializarea vectorului<br />
IF <strong>de</strong>pt_names IS NULL THEN<br />
DBMS_OUTPUT.PUT_LINE('Dupa initializare, vectorul este nul.');<br />
ELSE<br />
DBMS_OUTPUT.PUT_LINE('<strong>In</strong>ainte <strong>de</strong> initializare, vectorul nu este nul.');<br />
DBMS_OUTPUT.PUT_LINE('Vectorul are ' || <strong>de</strong>pt_names.COUNT || ' elemente.');<br />
END IF;<br />
END;<br />
o Cum accesam elementele din colectii<br />
Fiecare referire la un element dintr-o colectie implica numele colectiei si in<strong>de</strong>xul<br />
(subscriptul) inchis intre paranteze rotun<strong>de</strong>.<br />
collection_name(in<strong>de</strong>x)<br />
un<strong>de</strong> in<strong>de</strong>x este o expresie care este un intreg in cele mai <strong>multe</strong> cazuri dar poate fi<br />
si un VARCHAR2 pentru vectorii asociati in care cheile sunt <strong>de</strong>clarate ca siruri <strong>de</strong><br />
caractere.<br />
Limitele pentru subscript sunt:<br />
Pentru tabele grupate: 1 .. 2147483647<br />
Pentru vectori cu dim fixa 1 .. size_limit, (size_limit nu <strong>de</strong>paseste<br />
2147483647).<br />
Pentru vectorii asociati cu chei numerice -2147483648 la 2147483647.<br />
Pentru vectorii asociati cu chei <strong>de</strong> tip string lungimea cheii <strong>de</strong>pin<strong>de</strong> <strong>de</strong><br />
<strong>de</strong>claratia tipului VARCHAR2.<br />
Exemplu:<br />
DECLARE<br />
TYPE Roster IS TABLE OF VARCHAR2(15);<br />
names Roster := Roster('D Caruso', 'J Hamil', 'D Piro', 'R Singh');<br />
BEGIN<br />
FOR i IN names.FIRST .. names.LAST<br />
LOOP<br />
IF names(i) = 'J Hamil' THEN<br />
DBMS_OUTPUT.PUT_LINE(names(i));<br />
END IF;<br />
END LOOP;<br />
verify_name(names(3));<br />
END;<br />
--creati procedura<br />
PROCEDURE list_name(the_name VARCHAR2) IS<br />
BEGIN<br />
DBMS_OUTPUT.PUT_LINE(the_name);<br />
END;<br />
Exemplu: