Please disable your adblock and script blockers to view this page

Search this blog

Friday 23 March 2018

PL/SQL Basic Exit Loop


In PL/SQL Basic Loop all statements inside the block are executed at least once before loop termination, Basic loop encloses statement between LOOP and END LOOP and there must be an EXIT or EXIT-WHEN condition to terminate the loop

The syntax of Basic Exit loop is like this

LOOP

statements to execute

EXIT; or EXIT-WHEN

END LOOP;

See these examples for better understanding


PL/SQL EXIT Loop



DECLARE
--Counter Variable
i int:=0;
BEGIN
-- Start loop
LOOP
dbms_output.put_line('Value in loop is: '||i);
-- Increment Counter
i:=i+1;
-- Check condition
IF i>5 THEN
-- If true then exit
EXIT;
END IF;
END LOOP;
END;

and output is


PL/SQL EXIT WHEN Loop



DECLARE
--Counter Variable
i int:=10;
BEGIN
-- Start loop
LOOP
dbms_output.put_line('Value in loop is: '||i);
-- Increment Counter
i:=i+1;
-- Check condition and exit
EXIT WHEN i>15;
END LOOP;
END;

and output is


Cheers :) Happy Learning

No comments :

Post a Comment