Database/PLSQL
001 - [Oracle PL/SQL] Block Types
unsungIT
2024. 1. 31. 22:41
오라클 환경은 19c 입니다.
타입 블록은 아래처럼 3가지로 나누어지고 크게 2 부분으로 나눈다면
Anonymous 와 Subprograms 으로 나누어 진다.
Anonymous 와 Subprograms 차이를 간단히 표현하면 아래와 같다.
간단한 Anonymous 코드는 아래와 같다.
# SQL Developer 화면에서 문자 출력이 되지 않으면 아래 명령어를 실행시키면 된다.
SET SERVEROUTPUT ON
begin
dbms_output.put_line('--------------------------------------');
dbms_output.put_line('my first anonyms block');
end;
--we will do same Exercise using sql*plus
--------------------------------------------
begin
dbms_output.put_line('--------------------------------------');
dbms_output.put_line('this the first line');
dbms_output.put_line('this is the second line');
end;
---------------------------------------------
declare
begin
dbms_output.put_line('--------------------------------------');
dbms_output.put_line('hello world');
end;
----------------------------------------------
declare
v number;
begin
v:=5;
dbms_output.put_line('--------------------------------------');
dbms_output.put_line('hello world');
dbms_output.put_line(v);
end;
----------------------------------------------
화면 출력 결과는 아래와 같다.
--------------------------------------
my first anonyms block
PL/SQL procedure successfully completed.
--------------------------------------
this the first line
this is the second line
PL/SQL procedure successfully completed.
--------------------------------------
hello world
PL/SQL procedure successfully completed.
--------------------------------------
hello world
5
PL/SQL procedure successfully completed.
Sqlplus 에서 실행하는 방법은 아래와 같다.
SQL> begin
dbms_output.put_line('--------------------------------------');
dbms_output.put_line('my first anonyms block');
end; 2 3 4
5 /
--------------------------------------
my first anonyms block
PL/SQL procedure successfully completed.
# PL/SQL 을 끝낼때는 '/' 문자를 입력하면 된다.