Oracle开发包
| [日期:2012-04-15] |
来源:Linux社区
作者:tender001 |
[字体:大 中 小]
|
使用包重载
-
- create or replace package overload is
- function get_sal(eno number)return number;
- function get_sal(enames varchar2)return number;
- procedure fire_employee(eno number);
- procedure fire_employee(enames varchar2);
- end;
-
- create or replace package body overload is
- function get_sal(eno number)return number is
- v_sal emp.sal%type;
- begin
- select sal into v_sal from emp where empno=eno;
- return v_sal;
- exception
- when no_data_found then raise_application_error(-20020,'该雇员不存在');
- end get_sal;
- function get_sal(enames varchar2)return number is
- v_sal emp.sal%type;
- begin
- select sal into v_sal from emp where upper(ename)=upper(enames);
- return v_sal;
- exception
- when no_data_found then raise_application_error(-20020,'该雇员不存在');
- end get_sal;
- procedure fire_employee(eno number) is
- begin
- delete from emp where empno=eno;
- if sql%notfound then raise_application_error(-20020,'该雇员不存在');
- end if;
- end fire_employee;
- procedure fire_employee(enames varchar2) is
- begin
- delete from emp where upper(ename)=upper(enames);
- if sql%notfound then raise_application_error(-20020,'该雇员不存在');
- end if;
- end fire_employee;
- end overload;
-
-
- declare
- begin
- dbms_output.put_line(overload.get_sal('yang'));
- dbms_output.put_line(overload.get_sal(1111));
- end;
使用包构造过程
-
- create or replace package emp_pro_package is
- minsal number(6,2);
- maxsal number(6,2);
- procedure add_employee(eno number,enams varchar2,salary number,dno number);
- procedure upd_sal(eno number,salary number);
- procedure upd_sal(nams varchar2,salary number);
- end;
-
-
- create or replace package body overload is
- function get_sal(eno number)return number is
- v_sal emp.sal%type;
- begin
- select sal into v_sal from emp where empno=eno;
- return v_sal;
- exception
- when no_data_found then raise_application_error(-20020,'该雇员不存在');
- end get_sal;
- function get_sal(enames varchar2)return number is
- v_sal emp.sal%type;
- begin
- select sal into v_sal from emp where upper(ename)=upper(enames);
- return v_sal;
- exception
- when no_data_found then raise_application_error(-20020,'该雇员不存在');
- end get_sal;
- procedure fire_employee(eno number) is
- begin
- delete from emp where empno=eno;
- if sql%notfound then raise_application_error(-20020,'该雇员不存在');
- end if;
- end fire_employee;
- procedure fire_employee(enames varchar2) is
- begin
- delete from emp where upper(ename)=upper(enames);
- if sql%notfound then raise_application_error(-20020,'该雇员不存在');
- end if;
- end fire_employee;
- end overload;
-
-
- declare
- begin
- dbms_output.put_line(overload.get_sal('yang'));
- dbms_output.put_line(overload.get_sal(1111));
- end;
-
- /*
- .
- .
- 使用包构造过程
- */
-
- create or replace package emp_pro_package is
- minsal number(6,2);
- maxsal number(6,2);
- procedure add_employee(eno number,enams varchar2,salary number,dno number);
- procedure upd_sal(eno number,salary number);
- procedure upd_sal(nams varchar2,salary number);
- end;
-
-
- create or replace package body emp_pro_package is
- procedure add_employee(eno number,names varchar2,salary number,dno number)is
- begin
- if salary between minsal and maxsal then
- insert into emp(empno,ename,sal,deptno)values(eno,names,salary,dno);
- else
- raise_application_error(-20001,'工资不在范围内');
- end if;
- exception
- when dup_val_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;
-
- exception
- when dup_val_index then raise_application_error(-20002,'该雇员已经存在');
- end;
-
- procedure upd_sal(names varchar2,salary number)is
- begin
- if salary between minsal and maxsal then
- update emp set sal=salary where upper(ename)=upper(names);
- if sql%notfound then raise_application_error(-20003,'该雇员不存在');
- end if;
- else
- raise_application_error(-20001,'工资不在范围内');
- end if;
-
- exception
- when dup_val_index then raise_application_error(-20002,'该雇员已经存在');
-
- end;
-
-
- declare
- begin
- emp_pro_package.add_employee(1311,'MARY',3001,20);
- emp_pro_package.upd_sal('marry',20);
-
- end;
-
-
-
-
-
-
-
-
-
-

评论声明
- 尊重网上道德,遵守中华人民共和国的各项有关法律法规
- 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
- 本站管理人员有权保留或删除其管辖留言中的任意内容
- 本站有权在网站内转载或引用您的评论
- 参与本评论即表明您已经阅读并接受上述条款
|
|
|
|