29.11.2014 Views

Capitolul II Structurarea bazelor de date

Capitolul II Structurarea bazelor de date

Capitolul II Structurarea bazelor de date

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

50<br />

a. LOOP<br />

Un bloc LOOP - END LOOP permite <strong>de</strong>finirea unui ciclu din care se iese<br />

prin executarea unei instrucŃiuni EXIT. InstrucŃiunea EXIT este <strong>de</strong> regulă plasată<br />

într-un IF a cărui condiŃie trebuie să ajungă să fie satisfăcută pentru a se evita<br />

rularea blocului LOOP în ciclu infinit.<br />

Exemplu:<br />

credit_rating NUMBER := 0;<br />

BEGIN<br />

LOOP<br />

credit_rating := credit_rating + 1;<br />

IF credit_rating > 3 THEN<br />

EXIT; -- iesire imediata din loop<br />

END IF;<br />

END LOOP;<br />

-- dupa EXIT, executia se continuă <strong>de</strong> aici<br />

DBMS_OUTPUT.PUT_LINE ('Credit rating: ' || TO_CHAR(credit_rating));<br />

IF credit_rating > 3 THEN<br />

RETURN; -- în afara blocului LOOP se foloseşte RETURN, nu EXIT<br />

END IF;<br />

DBMS_OUTPUT.PUT_LINE ('Credit rating: ' || TO_CHAR(credit_rating));<br />

END;<br />

/<br />

Dacă ieşirea din ciclu se poate realiza printr-un simplu IF, se poate înlocui<br />

IF prin instrucŃiunea EXIT WHEN conditie_iesire.<br />

Exemplu:<br />

Exemplu:<br />

LOOP<br />

END LOOP;<br />

IF count > 100 THEN EXIT; ENDIF;<br />

EXIT WHEN count > 100;<br />

credit_rating := credit_rating + 1;<br />

EXIT WHEN credit_rating > 3

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

Saved successfully!

Ooh no, something went wrong!