包:包头:变量的声明与包体
建立包头:
create or replace package comm_pkg is
std_comm number:=0.1;包头变量定义 public
procedure reset_comm(new_comm number);包体中详细定义
end comm_pkg;
/
建立包体:
create or replace packag body comm_pkg is name与包头一致
function validate(comm number) return boolean is
max_comm employees.commission_pct%type;
begin
select max(commission_pct)into max_comm from employees;
return (comm between 0.0 and max_comm);
end validate;
procedure reset_comm(new_comm number)is
begin
if validate(new_comm) then
std_comm:=new_comm;
else raise_application_error(-20210,'bad commission');
end if
end reset_comm;
end comm_pkg;
/
exec xx/用户.comm_pkg.reset_comm(0.15);
exec schema.package_name.subprogram;
调用包头变量 包头.xx
create or replace package dept_pkg is
procedure add_deparment(depton number,namr varchar2:='unknown',loc number:=1700);
procedure add_deparmet(dempartment_id,departmen_name,location_id);
end dept_pkg;
create or replace package body dept_pkg is
procedure add_deparment(depton number,namr varchar2:='unknown',loc number:=1700);is
begin
inset into department(dempartment_id,departmen_name,location_id);
values(departon,name,loc);
end add_department;
procedure add_deparment(name varchar2:='unknown',loc number:=1700);is
begin
inset into department(dempartment_id,departmen_name,location_id);
values(departmets_seq.nextval,name,loc);
end add_department;
end dept_pkg;根据参数的不同,调用不同的函数。
PL/SQL包头与包体的定义
最新推荐文章于 2022-10-15 17:56:01 发布