You are on page 1of 2

ITE 407 ADVANCED DATABASES - Lab 5 PROCEDURES

Creating and Using PL/SQL Procedures

Objective

1. To demonstrate the creation of Procedures in PL/SQL


2. To demonstrate the use of Parameter Modes in PL/SQL Procedures

Background/Theory

Please take special note that this lab exercise has been recast from the Challenge questions in Lab
exercise 4.

Parameters are used to transfer data values to and from the calling environment and the procedure (or
subprogram). Parameters are declared in the subprogram header, after the name and before the
declaration section for local variables.
Parameters are subject to one of the three parameter-passing modes: IN, OUT, or IN OUT.

An IN parameter passes a constant value from the calling environment into the procedure.

An OUT parameter passes a value from the procedure to the calling environment.

An IN OUT parameter passes a value from the calling environment to the procedure and a
possibly different value from the procedure back to the calling environment using the
same parameter.

Parameters can be thought of as a special form of local variable, whose input values are initialized by
the calling environment when the subprogram is called, and whose output values are returned to the
calling environment when the subprogram returns control to the caller.

Tools/Equipment

The following resources will be required to successfully complete the tasks in this lab:

- Workstations running the Oracle client connected to an Oracle Server machine, or

- Workstations running the Oracle Express software.


Lab Activity

Using IN, OUT and IN OUT Parameters

1. Write out the following PL/SQL Procedure and observe the IN and OUT
parameters:

CREATE OR REPLACE PROCEDURE query_emp


(id IN employees.employee_id%TYPE,
name OUT employees.last_name%TYPE,
salary OUT employees.salary%TYPE) IS
BEGIN
SELECT last_name, salary INTO name, salary
FROM employees
WHERE employee_id = id;
END query_emp;

(a) Write an anonymous block that runs this procedure with variables to
take the parameters from the procedure created. [4]

(b) What is the significance of the supplied value in the anonymous


block? [2]

(c) What values will the emp_name and emp_sal parameters hold? [2]

(d) Use bind variables to write the execution of query_emp. [2]

2. Write a procedure using the IN OUT mode parameter, phone_no that


formats a 10-digit telephone number with the format (999)999-9999 (e.g. a
number 8006440555 would appear as (800)644-0555. [4]

April 11, 2017