* SQL*Plus 에서 패키지의 변수, 프로시저 사용
exec p(comm_pkg.std_comm)
exec comm_pkg.reset_comm(0.3)
exec p(comm_pkg.std_comm)
exec p(comm_pkg.validate(0.2))
==> 오류: ORA-06550: 줄 1, 열18:PLS-00302: 'VALIDATE' 구성 요소가 정의되어야 합니다
validate 함수는 패키지 본문(바디)에 정의되어 있음 --> private
* PL/SQL 블록에서 패키지의 변수, 프로시저 사용
declare
v_comm comm_pkg.std_comm%type := comm_pkg.std_comm;
begin
p('comm_pkg.std_comm : ' || comm_pkg.std_comm);
p('v_comm : ' || v_comm);
comm_pkg.std_comm := 0.15;
p('comm_pkg.std_comm : ' || comm_pkg.std_comm);
comm_pkg.reset_comm(0.12);
p('comm_pkg.std_comm : ' || comm_pkg.std_comm);
comm_pkg.reset_comm(0.5);
p('comm_pkg.std_comm : ' || comm_pkg.std_comm);
exception
when others then
p('오류가 발생하였어요~');
p('comm_pkg.std_comm : ' || comm_pkg.std_comm);
end;
/
-----------------------------------
create or replace package pack_ja
is
var1 number; -- public(global) variable
procedure p1 (p_in number); -- public subprogram
procedure p2 (p_in number); -- public subprogram
end;
/
create or replace package body pack_ja
is
var2 number; -- private variable
function f1 (a number) return boolean -- private subprogram
is
begin
if a < 3000 then
return true;
else
return false;
end if;
end;
procedure p1 (p_in number)
is
var3 number; -- local variable
begin
if f1(p_in) then
var2 := p_in + 1000;
else
var2 := p_in + 500;
end if;
p(var2);
end;
procedure p2 (p_in number)
is
var4 number; -- local variable
procedure local_proc (a varchar2) -- local subprogram
is
begin
p(a);
end;
begin
var2 := 1000;
local_proc('Korea');
local_proc('Seoul');
end;
end;
/
exec pack_ja.var1 := 1000;
set serveroutput on
exec pack_ja.p1(4000)
exec pack_ja.p2(100)
exec pack_ja.var2 := 1000; --> private component를 사용하려 하면 에러가 발생한다.
'Oracle > PL/SQL' 카테고리의 다른 글
15일차 # 3-17 (0) | 2012.04.24 |
---|---|
15일차 # 3-14: USER_SOURCE data dictionary (0) | 2012.04.24 |
15일차 # 3-10: PACKAGE BODY (0) | 2012.04.24 |
15일차 Chapter 3 - Packages I # 3-8: PACKAGE SPECIFICATION (0) | 2012.04.24 |
15일차 # 2-15: USER_SOURCE data dictionary view (0) | 2012.04.24 |