▣ 반복문
▣ 구구단 출력
SQL> create or replace procedure gugu
2 as
3 begin
4 for i in 1..9 loop
5 dbms_output.put_line(3 || 'x' || i || '=' || 3*i);
6 end loop;
7 end;
8 /
Procedure created.
SQL> exec gugu
PL/SQL procedure successfully completed.
SQL> show serveroutput
serveroutput OFF
SQL> set serveroutput on
SQL> exec gugu
3x1=3
3x2=6
3x3=9
3x4=12
3x5=15
3x6=18
3x7=21
3x8=24
3x9=27
PL/SQL procedure successfully completed.
▣ 파라미터 입력받아 출력
SQL> create or replace procedure plus(s1 number,s2 number)
2 as
3 begin
4 dbms_output.put_line('s1 + s1 =' || (s1+s2));
5 end;
6 /
Procedure created.
SQL> exec plus(1,2);
s1 + s1 =3
PL/SQL procedure successfully completed.
▣ 단 입력 받아 구구단 출력
SQL> create or replace procedure gugu2(dan number)
2 as
3 begin
4 for i in 1..9 loop
5 dbms_output.put_line(dan || 'x' || i || '=' || dan*i);
6 end loop;
7 end;
8 /
Procedure created.
SQL> exec gugu2(4);
4x1=4
4x2=8
4x3=12
4x4=16
4x5=20
4x6=24
4x7=28
4x8=32
4x9=36
PL/SQL procedure successfully completed.
댓글 없음:
댓글 쓰기