본문 바로가기

Database/PLSQL

048 - [Oracle PL/SQL] Package - visibility of components

<샘플코드에서 사용한 데이터는 HR 스키마이고, 오라클 설치시 생성할 수 있는 기본 스키마 입니다>

 

 

 

# c_var1/c_var2 can be referenced any place in package body 
# c_var3 can be referenced any place in package body 
# c_var4 can be referenced only in print procedure

create or replace package p_test
is
    c_var1 constant number:=10;
    c_var2 varchar2(100):='welcome';
    
    procedure print;
end;
/
create or replace package body p_test
is
    c_var3 varchar2(100):='hi there'; 
    procedure print
    is 
    c_var4 varchar2(100):='hi';

    begin
        dbms_output.put_line('this variable came from package spec. '||c_var1);
        dbms_output.put_line('this variable came from package spec. '||c_var2);
        dbms_output.put_line('this variable came from package body. '||c_var3);
        dbms_output.put_line('this variable came from print proced. '||c_var4);
    end;

end;
/



execute p_test.print;
---------------------------------------------------------------
this variable came from package spec. 10
this variable came from package spec. welcome
this variable came from package body. hi there
this variable came from print proced. hi