Advertisement
Albinutte

DBMS task 3

Nov 21st, 2014
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE OR REPLACE PACKAGE dept_pack AS
  2.     FUNCTION count_dept RETURN INT;
  3.     PROCEDURE total_salary(
  4.         department IN VARCHAR,
  5.         res OUT NUMBER);
  6.     PROCEDURE total_comm(
  7.         department IN VARCHAR,
  8.         res OUT NUMBER);
  9. END dept_pack;​
  10.  
  11. CREATE OR REPLACE PACKAGE BODY dept_pack AS
  12.     FUNCTION count_dept RETURN INT
  13.     IS
  14.     BEGIN  
  15.         DECLARE res INT;
  16.         BEGIN
  17.             SELECT COUNT(*) INTO res FROM dept;
  18.             RETURN res;  
  19.         END;
  20.     EXCEPTION
  21.         WHEN OTHERS THEN
  22.             log_info(SUBSTR(SQLERRM, 1, 100), 'dept_pack.count_dept');
  23.     END count_dept;
  24.     PROCEDURE total_salary(
  25.         department IN VARCHAR,
  26.         res OUT NUMBER)
  27.     IS
  28.     BEGIN
  29.         WITH joined AS (SELECT emp.sal AS sal, dept.dname AS name FROM emp INNER JOIN dept ON emp.deptno = dept.deptno)
  30.             SELECT SUM(sal) INTO res FROM joined WHERE name = department;
  31.         COMMIT;
  32.     EXCEPTION
  33.         WHEN OTHERS THEN
  34.             log_info(SUBSTR(SQLERRM, 1, 100), 'dept_pack.total_salary');
  35.     END total_salary;
  36.     PROCEDURE total_comm(
  37.         department IN VARCHAR,
  38.         res OUT NUMBER)
  39.     IS
  40.     BEGIN
  41.         WITH joined AS (SELECT emp.comm AS comm, dept.dname AS name FROM emp INNER JOIN dept ON emp.deptno = dept.deptno)
  42.             SELECT SUM(comm) INTO res FROM joined WHERE name = department;
  43.         COMMIT;
  44.     EXCEPTION
  45.         WHEN OTHERS THEN
  46.             log_info(SUBSTR(SQLERRM, 1, 100), 'dept_pack.total_comm');
  47.     END total_comm;
  48. END dept_pack;​
  49.  
  50. CREATE OR REPLACE PACKAGE emp_pack AS
  51.     PROCEDURE count_emp(
  52.         res OUT NUMBER);
  53.     PROCEDURE raise_all(
  54.         percent IN NUMBER);
  55.     PROCEDURE raise_position(
  56.         position IN VARCHAR2,
  57.         percent IN NUMBER);
  58. END emp_pack;​
  59.  
  60. CREATE OR REPLACE PACKAGE BODY emp_pack AS
  61.     PROCEDURE count_emp(
  62.         res OUT NUMBER)
  63.     IS
  64.     BEGIN
  65.         SELECT COUNT(*) INTO res FROM emp;
  66.         COMMIT;
  67.     EXCEPTION
  68.         WHEN OTHERS THEN
  69.             log_info(SUBSTR(SQLERRM, 1, 100), 'emp_pack.count_emp');
  70.     END count_emp;
  71.     PROCEDURE raise_all(
  72.         percent IN NUMBER)
  73.     IS
  74.     BEGIN
  75.         UPDATE emp SET sal = sal + sal * percent / 100;
  76.         COMMIT;
  77.     EXCEPTION
  78.         WHEN OTHERS THEN
  79.             log_info(SUBSTR(SQLERRM, 1, 100), 'emp_pack.raise_all');
  80.     END raise_all;
  81.     PROCEDURE raise_position(
  82.         position IN VARCHAR2,
  83.         percent IN NUMBER)
  84.     IS
  85.     BEGIN
  86.         UPDATE emp SET sal = sal + sal * percent / 100 WHERE job = position;
  87.         COMMIT;
  88.     EXCEPTION
  89.         WHEN OTHERS THEN
  90.             log_info(SUBSTR(SQLERRM, 1, 100), 'emp_pack.raise_position');
  91.     END raise_position;
  92. END emp_pack;​
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement