PLSQL 7 3 SG
PLSQL 7 3 SG
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:
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?
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