Oracle數(shù)據(jù)庫(kù)包的構(gòu)造過(guò)程實(shí)例
作者:痞子過(guò)
本文我們主要介紹了Oracle數(shù)據(jù)庫(kù)包的構(gòu)造過(guò)程實(shí)例,并給出了詳細(xì)的代碼,希望能夠?qū)δ兴鶐椭?/div>
Oracle數(shù)據(jù)庫(kù)包的構(gòu)造過(guò)程是沒(méi)有任何名稱的,它是在實(shí)現(xiàn)了包的其他過(guò)程之后,以begin開始,以end結(jié)束的部分。本文我們就介紹了一個(gè)構(gòu)造過(guò)程的實(shí)例,接下來(lái)就讓我們一起來(lái)了解一下這部分內(nèi)容吧。
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, '工資不在范圍內(nèi)');
- end if;
- exception
- when dup_val_on_index then
- raise_application_error(-20002, '該雇員已經(jīng)存在');
- 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, '不存在該雇員號(hào)');
- end if;
- else
- raise_application_error(-20001, '工資不在范圍內(nèi)');
- 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, '不存在該雇員號(hào)');
- end if;
- else
- raise_application_error(-20001, '工資不在范圍內(nèi)');
- end if;
- end;
3.構(gòu)造過(guò)程
- begin
- select min(sal), max(sal) into minsal, maxsal from emp;
- end;
關(guān)于Oracle數(shù)據(jù)庫(kù)包的構(gòu)造過(guò)程實(shí)例的知識(shí)就介紹到這里了,希望本次的介紹能夠?qū)δ兴斋@!
【編輯推薦】
責(zé)任編輯:趙鵬
來(lái)源:
博客園

相關(guān)推薦
















