begin

 begin

   execute immediate 'drop table players';

 exception

   when others then

     null;

 end;


 execute immediate 'create table players (no number

                                        , name varchar2(30))';

end;

/

-----------------------------------------

desc players



  * EXIT Statement: 루프를 빠져나오고 루프 문 바로 다음 문장으로 제어권을 넘김


    1) EXIT WHEN condition


declare

 i number := 1; -- counter 변수

begin

 loop

   insert into players

     values (i, 'Player '||to_char(i)||' entered.');

   i := i + 1; -- counter 변수 갱신

   exit when i > 10; -- 탈출 조건

 end loop;


 p(to_char(i-1)||' data inserted');

end;

/

-----------------------------------------

select * from players;



    2) IF condition THEN exit; END IF;


declare

 i number := 1;

begin

 loop

   insert into players 

     values (i, 'Player '||to_char(i)||' entered.');

   i := i + 1;

   if i > 10 then

     p('loop is terminated!');

     exit;

   end if;

 end loop;


p(to_char(i-1)||' data inserted');

end;

/

-----------------------------------------

select * from players;


+ Recent posts