1.包的构成:包规范与包体
(1)包规范
create package emp_pkg
is
procedure update_sal(name varchar2,newsal number);
function annual_income(name varchar2) return number;
end;
(2)包体
create or replace package body emp_pkg
is
procedure update_sal(name varchar2,newsal number)
is
begin
update test set sal=newsal where
lower(ename)=lower(name);
end;
function annual_income(name varchar2) return number
is
annual_salary number(7,2);
begin
select sal*12+nvl(comm,0) into annual_salary
from test where lower(ename)=lower(name);
return annual_salary;
end;
end;
//调用包中的过程:call emp_pkg.update_sal('JONES',3000);
//调用包中的函数:
SQL> var income number
SQL> call emp_pkg.annual_income('JONES') into :income;
(1)包规范
create package emp_pkg
is
procedure update_sal(name varchar2,newsal number);
function annual_income(name varchar2) return number;
end;
(2)包体
create or replace package body emp_pkg
is
procedure update_sal(name varchar2,newsal number)
is
begin
update test set sal=newsal where
lower(ename)=lower(name);
end;
function annual_income(name varchar2) return number
is
annual_salary number(7,2);
begin
select sal*12+nvl(comm,0) into annual_salary
from test where lower(ename)=lower(name);
return annual_salary;
end;
end;
//调用包中的过程:call emp_pkg.update_sal('JONES',3000);
//调用包中的函数:
SQL> var income number
SQL> call emp_pkg.annual_income('JONES') into :income;