Wednesday, June 23, 2010

For Loop In Oracle

Syntax For Loop In Orcale
FOR Contitions
   Loop Statements
END LOOP

Loop Start With 1 to 10
BEGIN
FOR i IN 1..10 LOOP
DBMS_OUTPUT.PUT_LINE('Current Number :'||i);
END LOOP;
END;
/

Loop Start With 10 to 17
BEGIN
FOR i IN 10..17 LOOP
DBMS_OUTPUT.PUT_LINE('Current Number :'||i);
END LOOP;
END;
/

Loop Start & End With variables value
DECLARE
StartValue NUMBER := 10;
EndValue   NUMBER := 20;
BEGIN
FOR i IN StartValue .. EndValue LOOP
DBMS_OUTPUT.PUT_LINE('Current Number :'||i);
END LOOP;
END;
/

No comments: