Unit V - Exception Handling
Unit V - Exception Handling
Faculty Handling
G. Sumalatha
Assistant Professor
Department of computer Technology
SKASC 1
Relational Database Management System- 22CTU08
SRI KRISHNA ARTS AND SCIENCE COLLEGE
DEPARTMENT OF COMPUTER TECHNOLOGY AND
DATA SCIENCE
SKASC 2
Relational Database Management System- 22CTU08
AGENDA
Recognize unhandled exceptions
List and useDefine PL/SQL exceptions
different types of PL/SQL exception handlers
Trap unanticipated errors
Describe the effect of exception propagation in nested blocks
Customize PL/SQL exception messages
SKASC 3
Relational Database Management System- 22CTU08
EXCEPTIONS
TOPIC LINK
Handling exception
https://youtu.be/P4U7Gzc2C3I
and types
Trapping of non
predefined oracle
https://youtu.be/itkqAotJp9c
server errors
SKASC 4
Relational Database Management System- 22CTU08
Objectives
After completing this lesson, you should be able to do the
following:
•Recognize unhandled exceptions
•List and useDefine PL/SQL exceptions
• different types of PL/SQL exception handlers
•Trap unanticipated errors
•Describe the effect of exception propagation in nested blocks
•Customize PL/SQL exception messages
SKASC 5
Relational Database Management System- 22CTU08
Example of an
Exception
DECLARE
v_lname VARCHAR2(15);
BEGIN
SELECT last_name INTO v_lname
FROM employees
WHERE first_name='John';
DBMS_OUTPUT.PUT_LINE ('John''s last name is :'
||v_lname);
END;
SKASC 6
Relational Database Management System- 22CTU08
Example of an Exception
DECLARE
v_lname VARCHAR2(15);
BEGIN
SELECT last_name INTO v_lname
FROM employees
WHERE first_name='John';
DBMS_OUTPUT.PUT_LINE ('John''s last name is :'
||v_lname);
EXCEPTION
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE (' Your select statement
retrieved multiple rows. Consider using a
cursor.');
END;
/
SKASC 7
Relational Database Management System- 22CTU08
SKASC 8
Relational Database Management System- 22CTU08
Handling Exceptions
Is the
exception Terminat
trapped? N e
o abruptly.
Ye
s
Exceptio Execute Propagate
n statements the
is raised. in the EXCEPTION
exception.
section.
Terminate
gracefully.
SKASC 9
Relational Database Management System- 22CTU08
Exception Types
– Predefined Oracle server
– Non-predefined Oracle server
– User-defined
SKASC 10
Relational Database Management System- 22CTU08
Trapping Exceptions
Syntax:
EXCEPTION
WHEN exception1 [OR exception2 . . .] THEN
statement1;
statement2;
. . .
[WHEN exception3 [OR exception4 . . .] THEN
statement1;
statement2;
. . .]
[WHEN OTHERS THEN
statement1;
statement2;
. . .]
SKASC 11
Relational Database Management System- 22CTU08
SKASC 12
Relational Database Management System- 22CTU08
SKASC 13
Relational Database Management System- 22CTU08
Trapping Non-Predefined
Oracle Server Errors
Non-predefined exceptions are similar to predefined exceptions;
however, they are not defined as PL/SQL exceptions in the Oracle server.
They are standard Oracle errors. You create exceptions with standard
Oracle errors by using the PRAGMA EXCEPTION_INIT function.
Such exceptions are called non-predefined exceptions.
You can trap a non-predefined Oracle server error by declaring it first.
The declared exception is raised implicitly.
In PL/SQL, PRAGMA EXCEPTION_INIT tells the compiler to
associate an exception name with an Oracle error number.
That enables you to refer to any internal exception by name and to write
a specific handler for it.
SKASC 15
Relational Database Management System- 22CTU08
Trapping Non-Predefined
Oracle Server Errors
Declarative EXCEPTION
section section
Name the Use PRAGMA Handle the raised
exception. EXCEPTION_INIT. exception.
SKASC 16
Relational Database Management System- 22CTU08
Non-Predefined Error
SUMMARY
SKASC 18
Relational Database Management System- 22CTU08
KEYWORDS
Exceptions
Usedefine PL/SQL Exceptions
Exception Handlers
Unanticipated Errors
Exception Propagation In Nested Blocks
Exception Messages
SKASC 19
Relational Database Management System- 22CTU08
MCQ
a) 2
b) 3
c) 4
c) 5
SKASC 20
Relational Database Management System- 22CTU08
MCQ
a) CASE_NOT_FOUND
b) COLLECTION_IS_NULL
c) ACCESS_INTO_NULLd
d) DUP_VAL_ON_INDEX
SKASC 21
Relational Database Management System- 22CTU08
MCQ
a) "06530"
b) "06592"
c) "06531"
d) "01722"
SKASC 22
Relational Database Management System- 22CTU08
MCQ
SKASC 23
Relational Database Management System- 22CTU08
MCQ
a) Default Keyword
b) WHEN THEN Keyword
c) WHEN Keyword
d) WHEN others THEN Keyword
SKASC 24
Relational Database Management System- 22CTU08
NEXT SESSION
Handling Exceptions
SKASC 25