Oracle学习之过程

create or replace procedure add_em
(eno number,name varchar2,sal number,
job varchar2 default 'CLERK',dno number)
is
e_integrity exception;
pragma exception_init(e_integrity,-2291);
begin
insert into emp(empno,ename,sal,job,deptno)
values (eno,name,sal,job,dno);
exception
when dup_val_on_index then
raise_application_error(-20000.'雇员编号不能重复');
when e_integrity then
raise_application_error(-20001,'部门编号不存在');
end;
/

create or replace function get_val(name in varchar2)
return number
as
v_sal emp.sal%TYE;
begin
select sal into v_sal from empwhere upper(ename)=uper(name);
return v_sal;
exception
when no_data_found then
raise_application_error(-20000,'该雇员不存在');
end;
/

create or replace package emp_package is 
function get_name(no number) return varchar2;
procedure add_employee(
no number,name varchar2,salary number,dno number);
procedure update_sal(name varchar2,salary number);
procedure fire_employee(name varchar2);
procedure fire_employee(no number);
end;
/

create or replace package body em_package
is
function get_name(no number) return varchar2 is 
name varchar2(10);
begin
select ename into name from emp where empno=no;
return name;
end;
procedure add_employee(no number,name varchar2,salary number,dno number)
is
begin
insert into emp (empno,ename,sal,depno)
values (no,name,salary,dno);
end;
procedure update_sal(name varchar2,salary number)
is
begin
update emp set sal=salary
where upper(ename)=upper(name);
end;
procedure fire_employee(name varchar2)
is
begin
delete from emp where upper(name)=upper(name);
end;
procedure fire_employee(no number)
is 
begin
delete from emp where empno=no;
end;
end emp_package;
/

commit;

 

posted @ 2016-03-23 20:25  道心不可练  阅读(253)  评论(0编辑  收藏  举报