Lab 14.1 Exercise Answers
A1: | Answer: The specification for the package manage_students has been compiled into the database. The specification for the package now indicates that there is one procedure and one function. The procedure find_sname requires one IN parameter, which is the student ID, and it returns two OUT parameters, one being the student's first name and the other being the student's last name. The function id_is_good takes in a single parameter of a student ID and returns a Boolean (true or false). Although the body has not yet been entered into the database, the package is still available for other applications. For example, if you included a call to one of these procedures in another stored procedure, that procedure would compile (but would not execute). | ||
b) | If the following script was run from a SQL*PLUS session, what would the result be and why?
| ||
A2: | Answer: The procedure cannot run because only the specification for the procedure exists in the database, not the body. The SQL*Plus session returns the following:
| ||
Chapter 12 and the function new_instructor_id from Chapter 13. | |||
A3: | Answer:
|
A1: | Answer: The package body manage_students is compiled into the database. The package contains the procedure manage_students.find_sname, which accepts the parameter student_id and returns the student's last_name and first_name from the Student table. |
A2: | Answer:
|
A1: | Answer: This is a correct PL/SQL block for running the function and the procedure in the package manage_students. If an existing student_id is entered, then the name of the student is displayed. If the id is not valid, then the error message is displayed. |
A2: | Answer: Initially the following appears:
|
A3: | Answer:
|
14.1.4 Answers
a) | Replace the last lines of the manage_students package specification with the following and recompile the package specification:Replace the end of the body with the following and recompile the package body: What have you added to the manage_student package? |
A1: | Answer: A private function, student_count_privs, and a public procedure, display_student_count, calling the private function. |
b) | If you run the following from your SQL*PLUS session, what are the results?
|
A2: | Answer: Since the private function, student_count_privs, cannot be called from outside the package, you receive an error message as follows:
|
c) | If you were to run the following, what do you expect to see?
| |||||||
A3: | Answer: This is a valid method of running a procedure. A line is displayed indicating the number of students in the database. Note that the procedure in the package manage_ students is using the private function student_count_priv to retrieve the student count.
|