PL/SQL包头与包体的定义

包:包头:变量的声明与包体
	建立包头:
	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;根据参数的不同,调用不同的函数。
	

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值