0% found this document useful (0 votes)
61 views

Tutorial 06

This document provides instructions for a tutorial exercise on stored procedures in Oracle. Students are asked to write a stored procedure called addAccident() that inserts new accident records into the accident and involved database tables. The procedure should take parameters for the report number, registration number, location, date, damage amount, and assume the driver is the owner. Students are then asked to call the procedure to add at least one new accident record. Tips are provided on the syntax for creating stored procedures in Oracle and how to view errors.

Uploaded by

satcbe84
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Tutorial 06

This document provides instructions for a tutorial exercise on stored procedures in Oracle. Students are asked to write a stored procedure called addAccident() that inserts new accident records into the accident and involved database tables. The procedure should take parameters for the report number, registration number, location, date, damage amount, and assume the driver is the owner. Students are then asked to call the procedure to add at least one new accident record. Tips are provided on the syntax for creating stored procedures in Oracle and how to view errors.

Uploaded by

satcbe84
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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.

You might also like