Monday, 4 March 2013

LOOPS In PLSQL

CREATE TABLE TEMP(empno NUMBER,ename VARCHAR2(30));
Loop…End loop : Inserting multiple records and exiting based on a condition.
 declare
  nCode number (5);
 begin
  nCode := 101;
   loop
 insert into temp(empno,ename)     values (nCode, 'Somebody');
   nCode := nCode + 1;
   if nCode > 110 then
    exit;
   end if;
  end loop;
 end;
PL/SQL procedure successfully completed.

The While Loop:
Inserting multiple records and exiting based on a condition.
 declare
 nCode number (5);
 begin
  nCode := 101;
  while nCode <= 110
  loop
insert into temp(empno,ename)    values (nCode, 'Somebody');
   nCode := nCode + 1;
 end loop;
 end;
PL/SQL procedure successfully completed.

The For Loop:
Inserting multiple records and exiting based on a condition.
 begin
  for ncode in 101..110
  loop
 insert into temp(empno,ename)     values (ncode, 'somebody');
   end loop;
  end;
PL/SQL procedure successfully completed.

No comments:

Post a Comment