본문 바로가기

ORACLE SQL

[ORACLE] SQL 반복문 - FOR문, WHILE문[ORACLE] SQL 반복문 - FOR문, WHILE문

728x90

WHILE문

1
2
3
4
5
6
7
8
9
10
11
12
13
declare
    num number :=1;
begin
   Loop
         dbms_output.put_line('while:'||num);
         num := num + 1;
         if(num>5) then
            exit;
         end if;
    end loop;
end;
/
cs

 

FOR문

 

1
2
3
4
5
6
7
8
9
declare


begin
    for i in 1..5 loop
           dbms_output.put_line('for:'||i);
    end loop;
end;
/
cs

 

 

WHILE 조건문

1
2
3
4
5
6
7
8
9
declare
    num number :=1;
begin
    while(num <=5) loop
         dbms_output.put_line('while:'||num);
         num := num + 1;
    end loop;
end;
/
cs