Thursday, June 24, 2010

While Loop In Oracle

Syntax WHILE Loop In Orcale
WHILE Contitions
   Loop Statements
END LOOP

While Loop Start With 1 to 10
DECLARE
i NUMBER :=0;
BEGIN
WHILE i < 10 LOOP
i:= i+1;
DBMS_OUTPUT.PUT_LINE('Current Number :'||i);
END LOOP;
END;
/

While Loop Start With 10 to 17
DECLARE
i NUMBER :=10;
BEGIN
WHILE i < 17 LOOP
i:= i+1;
DBMS_OUTPUT.PUT_LINE('Current Number :'||i);
END LOOP;
END;
/

While Loop Start & End With variables value
DECLARE
StartValue NUMBER := 10;
EndValue   NUMBER := 20;
BEGIN
WHILE StartValue < EndValue LOOP
StartValue := StartValue + 1;
DBMS_OUTPUT.PUT_LINE('Current Number :'||StartValue);
END LOOP;
END;
/

No comments: