School of Information Technologies
Dr. Uwe Röhm
COMP5138: Relational Database Management Systems 1.Sem./2005
Tutorial 6: Stored Procedures and PL/SQL
28.04.2004
Introduction
In this exercise, we will have a look at stored procedures in Oracle. As there are no
tutorials this week due to Anzac day, we will just have a short look into these topics.
You should be able to solve the following exercise either within the School or back home
(assuming that you have internet access). You only need access to our courses web site.
There, you will find both the online documentation for Oracle PL/SQL, as well as access
to our course’s Oracle database via iSQL*Plus (its web front-end we used so far).
Question 1: Oracle Stored Procedure
Log into our course database with the web front-end iSQL*Plus and answer the following
two questions:
a) Write a stored procedure addAccident() which adds a new accident to the database.
The procedure should take the report number, the registration number of the car in-
volved, the location string, and the date and the damage amount of the accident as
parameters, and insert corresponding tuples into both the accident and the involved
relations. Assume that the involved driver is actually the owner of the car.
b) Add at least one new accident into your database by calling your stored procedure
addAccident().
Tip 1: The general syntax for creating a new stored procedure with Oracle differs from
the SQL1999 standard. It is as follows:
CREATE OR REPLACE PROCEDURE name ( param1 , ..., paramN )
AS
BEGIN
... SQL-DML statements and PL/SQL code ...
END;
where name is the name of the stored procedure and paramX is a parameter declaration
of the form parametername IN SQL-domain-type
1
Tip 2: In case of an error, Oracle just answers with Warning: Procedure created with
compilation errors. To see more details on this compilation error, add the following two
lines after your procedure code (the first line is just a ’/’):
/
SHOW ERRORS;
Tip 3: Start with creating a new empty stored procedure which takes the correct param-
eters but just adds the first tuple into accident. If this works, think about how to add the
second tuple into involved where you have to query two values from the database. Ac-
tually, you can solve this exercise without using PL/SQL at all but just with a sequence of
SQL commands. The solution is very similar to the solution of question 4 of the previous
tutorial.