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

PLSQL 7 3 SG

This document provides updates and examples related to handling exceptions in Oracle PL/SQL. Key points include: - Situations where a statement may execute successfully but still result in an error from the user's perspective are discussed, like an UPDATE modifying no rows. - Reminders that exceptions prevent further execution and that IF SQL%ROWCOUNT can check for no rows instead of SQL%NOTFOUND. - User-defined exceptions allow returning more meaningful error messages to users than generic Oracle errors. - The RAISE and RAISE_APPLICATION_ERROR statements are used to explicitly raise user-defined exceptions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

PLSQL 7 3 SG

This document provides updates and examples related to handling exceptions in Oracle PL/SQL. Key points include: - Situations where a statement may execute successfully but still result in an error from the user's perspective are discussed, like an UPDATE modifying no rows. - Reminders that exceptions prevent further execution and that IF SQL%ROWCOUNT can check for no rows instead of SQL%NOTFOUND. - User-defined exceptions allow returning more meaningful error messages to users than generic Oracle errors. - The RAISE and RAISE_APPLICATION_ERROR statements are used to explicitly raise user-defined exceptions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Release Date: August, 2015

Updates:

1
2
3
Ask students to think of situations where the Oracle server would execute a statement successfully (and
therefore not raise an exception automatically) but there is still an “error” from the user’s viewpoint.
Possible examples:

A DML UPDATE or DELETE statement modifies no rows


A SELECT statement successfully reads a row which should not exist yet
A Stock Clerk has been identified as a manager, but our business rules state that clerks cannot be
managers.

4
5
6
Remind students that an UPDATE or DELETE DML statement is treated as successful by the server even if it
modifies no rows. Therefore the Oracle server will not automatically raise an exception in this case. If we
want to raise an exception, we must do it ourselves.

7
8
9
10
Remind students that when any kind of exception is raised, the rest of the executable section is not
executed. Therefore in the slide example, if the UPDATE modifies no rows, the COMMIT will not be
executed.

Instead of using IF SQL%NOTFOUND THEN … we could have coded: IF SQL%ROWCOUNT = 0 THEN ...

11
12
13
14
15
16
17
18
19
Note that an error raised by RAISE_APPLICATION_ERROR is an unhandled exception which is propagated
back to the calling environment. The whole idea is to allow the calling application to display a business-
meaningful error message to the user. If the exception was handled successfully within the PL/SQL block,
the application would not see the error at all.

20
Ask students to imagine that another member of their family is using a computer and sees an error
message on the screen. Which of these messages would their family member rather see?

ORA-01403: no data found


ORA-20201: This manager has no employees

21
In this example, when an invalid last name is entered, the user-defined exception e_name is raised using its
error number -20999. Because the EXCEPTION_INIT pragma was used to define the error name e_name
and its error code –20999, when the error code is raised, the exception handler for e_name is run and the
exception is not propagated to the calling environment.

22
User-Defined errors - These errors are not automatically raısed by the Oracle Server, but are defined by the
programmer and are specific to the programmer's code.
RAISE – Use this statement to raise a named exception.
RAISE_APPLICATION_ERROR – A procedure used to return user-defined error messages from stored
subprograms.

23
24
25

You might also like