CREATE OR REPLACE PACKAGE employee_pkg AS
PROCEDURE New_Employee (
p_empname IN employee.emp_name%type,
p_salary IN employee.emp_salary%type,
p_sdate IN employee.emp_sdate%type,
p_deptno IN department.dept_no%type);
PROCEDURE Del_Employee (
p_empname IN employee.emp_name%type);
END employee_pkg;
/
show errors;
CREATE OR REPLACE PACKAGE BODY employee_pkg
AS
PROCEDURE New_Employee (
p_empname IN employee.emp_name%type,
p_salary IN employee.emp_salary%type,
p_sdate IN employee.emp_sdate%type,
p_deptno IN department.dept_no%type)
IS
Dept_Count number;
INVALID_DEPARTMENT exception;
BEGIN
select count(*) into Dept_Count
from department where dept_no = p_deptno;
if Dept_Count = 1 then
insert into EMPLOYEE values
( employeeNo.NextVal,
p_empname,
p_salary,
p_sdate,
p_deptno);
update department set dept_empcnt = dept_empcnt + 1 where dept_no = p_deptno;
commit;
else
raise INVALID_DEPARTMENT;
end if;
exception
when INVALID_DEPARTMENT then
raise_application_error(-20001, 'Invalid Department - INSERT UNSUCCESSFUL');
END New_Employee;
PROCEDURE DEL_EMPLOYEE(p_empname IN employee.emp_name%type)
IS
INVALID_DEPARTMENT exception;
INVALID_EMPLOYEE exception;
EMPCOUNT number;
v_deptNo department.dept_no%type;
BEGIN
select count(empname) INTO EMPCOUNT, dept_no INTO v_deptNo from employee
where empname = p_empname;
if EMPCOUNT > 0 then
delete from employee where empname = p_empname;
update department set dept_empcnt = dept_empcnt -1 where dept_no = v_deptNo;
commit;
else
raise INVALID_EMPLOYEE;
end if;
EXCEPTION
when INVALID_EMPLOYEE then
raise_application_error(-20001, 'Invalid Employee - DELETE UNSUCCESSFUL');
End Del_Employee;
END employee_pkg;
/
show errors;
PROCEDURE New_Employee (
p_empname IN employee.emp_name%type,
p_salary IN employee.emp_salary%type,
p_sdate IN employee.emp_sdate%type,
p_deptno IN department.dept_no%type);
PROCEDURE Del_Employee (
p_empname IN employee.emp_name%type);
END employee_pkg;
/
show errors;
CREATE OR REPLACE PACKAGE BODY employee_pkg
AS
PROCEDURE New_Employee (
p_empname IN employee.emp_name%type,
p_salary IN employee.emp_salary%type,
p_sdate IN employee.emp_sdate%type,
p_deptno IN department.dept_no%type)
IS
Dept_Count number;
INVALID_DEPARTMENT exception;
BEGIN
select count(*) into Dept_Count
from department where dept_no = p_deptno;
if Dept_Count = 1 then
insert into EMPLOYEE values
( employeeNo.NextVal,
p_empname,
p_salary,
p_sdate,
p_deptno);
update department set dept_empcnt = dept_empcnt + 1 where dept_no = p_deptno;
commit;
else
raise INVALID_DEPARTMENT;
end if;
exception
when INVALID_DEPARTMENT then
raise_application_error(-20001, 'Invalid Department - INSERT UNSUCCESSFUL');
END New_Employee;
PROCEDURE DEL_EMPLOYEE(p_empname IN employee.emp_name%type)
IS
INVALID_DEPARTMENT exception;
INVALID_EMPLOYEE exception;
EMPCOUNT number;
v_deptNo department.dept_no%type;
BEGIN
select count(empname) INTO EMPCOUNT, dept_no INTO v_deptNo from employee
where empname = p_empname;
if EMPCOUNT > 0 then
delete from employee where empname = p_empname;
update department set dept_empcnt = dept_empcnt -1 where dept_no = v_deptNo;
commit;
else
raise INVALID_EMPLOYEE;
end if;
EXCEPTION
when INVALID_EMPLOYEE then
raise_application_error(-20001, 'Invalid Employee - DELETE UNSUCCESSFUL');
End Del_Employee;
END employee_pkg;
/
show errors;