11.02.2014 Views

PL/SQL Loops - Tutorials Point

PL/SQL Loops - Tutorials Point

PL/SQL Loops - Tutorials Point

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.

The following prog ram illustrates the concept:<br />

DECLARE<br />

i number(1);<br />

j number(1);<br />

BEGIN<br />

><br />

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

><br />

FOR j IN 1..3 LOOP<br />

dbms_output.put_line('i is: '|| i || ' and j is: ' || j);<br />

END loop inner_loop;<br />

END loop outer_loop;<br />

END;<br />

/<br />

When the above code is executed at <strong>SQL</strong> prompt, it produces the following result:<br />

i is: 1 and j is: 1<br />

i is: 1 and j is: 2<br />

i is: 1 and j is: 3<br />

i is: 2 and j is: 1<br />

i is: 2 and j is: 2<br />

i is: 2 and j is: 3<br />

i is: 3 and j is: 1<br />

i is: 3 and j is: 2<br />

i is: 3 and j is: 3<br />

<strong>PL</strong>/<strong>SQL</strong> procedure successfully completed.<br />

The Loop Control Statements<br />

Loop control statements chang e execution from its normal sequence. When execution leaves a scope, all<br />

automatic objects that were created in that scope are destroyed.<br />

<strong>PL</strong>/<strong>SQL</strong> supports the following control statements. Labeling loops also helps in taking the control outside a loop.<br />

Click the following links to check their details.<br />

Control Statement<br />

EXIT statement<br />

CONTINUE statement<br />

GOTO statement<br />

Description<br />

The Exit statement completes the loop and control passes to the statement<br />

immediately after END LOOP<br />

Causes the loop to skip the remainder of its body and immediately retest its<br />

condition prior to reiterating .<br />

Transfers control to the labeled statement. Thoug h it is not advised to use<br />

GOTO statement in your prog ram.

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

Saved successfully!

Ooh no, something went wrong!