Sei sulla pagina 1di 8

HTTP 504 Database Design and Development

Writing PL/SQL Code Stored Procedures


How to Handle Errors and Handle Stored Procedure Execution
When writing PL/SQL stored procedures the details on errors are hidden from you. This set of notes will show you how
to find your errors in the code so you will be able to fix them.

The following piece of code has been written and you will notice it resulted in PL/SQL errors.

1
At least you are told there are errors, but that is about all you are told. Now our investigation begins.

In the Connections navigator expand the Procedures node and you will notice your code for the procedure you just
complied has a red cross overlaying the object icon. This indicates the object was compiled with errors.

Select the Procedure name in the list.

Here the Procedure UPDATE_ENROLLMENT_GRADE is selected. You will notice the screen has changed. You can still see
your code but if you look on the far right of the SQL Developer application you will notice three small red rectangles.
(Thank goodness I can print in colour).

2
These red rectangles indicate errors in you code and where they errors occur. You can roll your mouse over these to see
the nature of your errors.

3
There are three errors indicated doing a mouse over on the red rectangles in the right side margin displays more details
on the errors.

The object is to now fix the errors.

An additional comma was placed after the last entry of the Parameter Declarations List. The comma needs to be
removed.

This has removed one of the red rectangles. Now the procedure needs to have remaining errors fixed. You will also
notice WHERE has been spelled incorrectly, as WHRE.

4
After fixing the spelling foe WHERE and compiling again you will notice that it removed the final two errors and the code
has compiled with no errors. The red cross has been replaced with a green dot to indicate the code compiled fine.

If you select the Procedure name in the Connections navigator you will notice there are no red rectangles remaining. You
will see a green square that indicates the code compiled correctly.

5
How to Use a Stored Procedure
A SELECT statement is used to show the current values of a record in the ENROLLMENT table.

The stored procedure is now used to update the grade for student id 6 and course section id 12 to a grade of B. You will
notice when the SELECT was performed the grade was a NULL value.

6
Check the data again to see the changes.

The CALL statement can also be used in place of EXECUTE.

EXECUTE is generally used instead of CALL.

7
You could also execute through an anonymous PL/SQL program.

This concludes how to handle errors and how to use a Stored Procedure.

Potrebbero piacerti anche