Oracle数据库包的构造过程是没有任何名称的,它是在实现了包的其他过程之后,以begin开始,以end结束的部分。本文我们就介绍了一个构造过程的实例,接下来就让我们一起来了解一下这部分内容吧。
1.包头
- create or replace package pkg_emp is
- minsal number(6, 2);
- maxsal number(6, 2);
- procedure add_employee(eno number,
- name varchar2,
- salary number,
- dno number);
- procedure upd_sal(eno number, salary number);
- procedure upd_sal(name varchar2, salary number);
- end pkg_emp;
2.包体
- create or replace package body pkg_emp is
- procedure add_employee(eno number,
- name varchar2,
- salary number,
- dno number) is
- begin
- if salary between minsal and maxsal then
- insert into emp
- (empno, ename, sal, deptno)
- values
- (eno, name, salary, dno);
- else
- raise_application_error(-20001, '工资不在范围内');
- end if;
- exception
- when dup_val_on_index then
- raise_application_error(-20002, '该雇员已经存在');
- end;
- procedure upd_sal(eno number, salary number) is
- begin
- if salary between minsal and maxsal then
- update emp set sal = salary where empno = eno;
- if sql%notfound then
- raise_application_error(-20003, '不存在该雇员号');
- end if;
- else
- raise_application_error(-20001, '工资不在范围内');
- end if;
- end;
- procedure upd_sal(name varchar2, salary number) is
- begin
- if salary between minsal and maxsal then
- update emp set sal = salary where upper(ename) = upper(name);
- if sql%notfound then
- raise_application_error(-20004, '不存在该雇员号');
- end if;
- else
- raise_application_error(-20001, '工资不在范围内');
- end if;
- end;
3.构造过程
- begin
- select min(sal), max(sal) into minsal, maxsal from emp;
- end;
关于Oracle数据库包的构造过程实例的知识就介绍到这里了,希望本次的介绍能够对您有所收获!
【编辑推荐】