Homework Week 7.docx - Homework Week#7 PL/SQL Virtual...

This preview shows 1 out of 3 pages.

Homework Week #7 PL/SQL Virtual Training 1. First some questions about packages, what they can contain, what they are made up of and how we find out which ones we have access to in our accounts. A. Name at least four objects that can be put into a package. Procedures, Functions, Variables, Cursors, Exceptions, Constants. B. Name the two components of a package and explain the difference between them. Specification (or Spec) and Body. The Specification declares the subprograms in the package, while the Body contains the detailed code of the subprograms. C. Which of the two components must be created first, and why? The Specification must be created first. The Body is optional but the Specification is not. Therefore a Spec can exist without a Body, but a Body cannot exist without a Spec. D. Write a query against a Data Dictionary view to show you a list of packages you own. SELECT * FROM user_objects WHERE object_type LIKE 'PACK%'; 2. Create the specification for the check_emp_pkg which you studied in this lesson. The specification should declare a constant and two procedures, as follows: g_max_length_of_service, datatype NUMBER, initialized to 100 chk_hiredate with one input parameter having the same datatype as employees.hire_date chk_dept_mgr with two input parameters having the same datatypes as employees.employee_id and employees.manager_id. CREATE OR REPLACE PACKAGE check_emp_pkg IS g_max_length_of_service CONSTANT NUMBER := 100; PROCEDURE chk_hiredate (p_date IN employees.hire_date%TYPE); PROCEDURE chk_dept_mgr (p_empid IN employees.employee_id%TYPE, p_mgr IN departments.manager_id%TYPE); END check_emp_pkg;
Image of page 1

Subscribe to view the full document.

3. Create the package body for check_emp_pkg. Remember that the names and parameters of the procedures in the body must be identical to those in the specification, or the body will not compile. The code for chk_hiredate should RAISE_APPLICATION_ERROR if the employee was hired more than 100 years ago (hint: use MONTHS_BETWEEN, comparing with g_max_length_of_service * 12). The second procedure, chk_dept_mgr, accepts two input parameters: an employee_id and a manager_id. The code should find the manager of the employee’s department and check whether this manager has the same manager_id as the second parameter. If the manager_id is the same, display a suitable “success” message; if they are different, raise an application error. Include an exception handler for NO_DATA_FOUND.
Image of page 2
Image of page 3
You've reached the end of this preview.
  • Spring '16
  • Subroutine, Call stack, Control flow

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern