Oracle数据库包的构造过程实例

Oracle数据库包的构造过程是没有任何名称的,它是在实现了包的其他过程之后,以begin开始,以end结束的部分。本文我们就介绍了一个构造过程的实例,接下来就让我们一起来了解一下这部分内容吧。

1.包头

 
 
  1. create or replace package pkg_emp is  
  2.   minsal number(6, 2);  bb
  3.   maxsal number(6, 2);  
  4.   procedure add_employee(eno    number,  
  5.                          name   varchar2,  
  6.                          salary number,  
  7.                          dno    number);  
  8.   procedure upd_sal(eno number, salary number);  
  9.   procedure upd_sal(name varchar2, salary number);  
  10. end pkg_emp; 

2.包体

 
 
  1. create or replace package body pkg_emp is  
  2.  
  3.   procedure add_employee(eno    number,  
  4.                          name   varchar2,  
  5.                          salary number,  
  6.                          dno    number) is  
  7.   begin  
  8.     if salary between minsal and maxsal then  
  9.       insert into emp  
  10.         (empno, ename, sal, deptno)  
  11.       values  
  12.         (eno, name, salary, dno);  
  13.     else  
  14.       raise_application_error(-20001, '工资不在范围内');  
  15.     end if;  
  16.   exception  
  17.     when dup_val_on_index then  
  18.       raise_application_error(-20002, '该雇员已经存在');  
  19.   end;  
  20.  
  21.   procedure upd_sal(eno number, salary number) is  
  22.   begin  
  23.     if salary between minsal and maxsal then  
  24.       update emp set sal = salary where empno = eno;  
  25.       if sql%notfound then  
  26.         raise_application_error(-20003, '不存在该雇员号');  
  27.       end if;  
  28.     else  
  29.       raise_application_error(-20001, '工资不在范围内');  
  30.     end if;  
  31.   end;  
  32.  
  33.   procedure upd_sal(name varchar2, salary number) is  
  34.   begin  
  35.     if salary between minsal and maxsal then  
  36.       update emp set sal = salary where upper(ename) = upper(name);  
  37.       if sql%notfound then  
  38.         raise_application_error(-20004, '不存在该雇员号');  
  39.       end if;  
  40.     else  
  41.       raise_application_error(-20001, '工资不在范围内');  
  42.     end if;  
  43.   end; 

3.构造过程

 
 
  1. begin    
  2. select min(sal), max(sal) into minsal, maxsal from emp;    
  3. end;  

关于Oracle数据库包的构造过程实例的知识就介绍到这里了,希望本次的介绍能够对您有所收获!

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26914683/viewspace-768641/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/26914683/viewspace-768641/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值