FOR loop in PL/SQL

TO DISPLAY 1 TO 10 IN REVERSE ORDER

DECLARE
I NUMBER:=10;
BEGIN
DBMS_OUTPUT.PUT_LINE('REVERSE NUMBER 1-10 ');
FOR I IN REVERSE 1..10 LOOP
DBMS_OUTPUT.PUT_LINE(I);
END LOOP;
END;

**********************************************
>EVEN NUMBER BETWEEN 1 TO 100

DECLARE
NUM INT;
BEGIN
DBMS_OUTPUT.PUT_LINE('EVEN NUMBERS: ');
FOR NUM IN 1..100
LOOP
IF MOD(NUM,2)=0 THEN
DBMS_OUTPUT.PUT_LINE(' '||NUM);
END IF;
END LOOP;
END;

***************************************
declare
 cursor c1 is select * from emp;
  r emp%rowtype;
 Begin
open c1;
 loop
 fetch c1 into r;
 exit when c1%notfound;
dbms_output.put_line(r.ename);
 end loop;
  close c1;
  end;
************************************
declare
 cursor c1 is select * from emp;
 Begin
for r in c1
loop
  dbms_output.put_line(r.ename||' '||r.sal);
end loop;
end;
***********************************

Previous
Next Post »