Professional Documents
Culture Documents
PL/SQL
7-2
Trapping Oracle Server Exceptions
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 3
Trapping Oracle Server Exceptions
Objectives
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 4
Trapping Oracle Server Exceptions
Purpose
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 5
Trapping Oracle Server Exceptions
Purpose
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 6
Trapping Oracle Server Exceptions
Exception Types
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 7
Trapping Oracle Server Exceptions
Handling Exceptions with PL/SQL
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 8
Trapping Oracle Server Exceptions
Handling Exceptions with PL/SQL
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 9
Trapping Oracle Server Exceptions
Two Types of Oracle Server Errors
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 10
Trapping Oracle Server Exceptions
Two Types of Oracle Server Errors
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 11
Trapping Oracle Server Exceptions
Two Types of Oracle Server Errors
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 12
Trapping Oracle Server Exceptions
Trapping Predefined Oracle Server Errors
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 13
Trapping Oracle Server Exceptions
Trapping Predefined Oracle Server Errors
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 14
Trapping Oracle Server Exceptions
Trapping Predefined Oracle Server Errors
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 15
Trapping Oracle Server Exceptions
Trapping Several Predefined Oracle Server
Errors
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 16
Trapping Oracle Server Exceptions
Trapping Non-Predefined Oracle Server
Errors
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 17
Trapping Oracle Server Exceptions
Trapping Non-Predefined Oracle Server
Errors
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 18
Trapping Oracle Server Exceptions
Non-Predefined Error
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 19
Trapping Oracle Server Exceptions
Non-Predefined Error
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 20
Trapping Oracle Server Exceptions
Non-Predefined Error
DECLARE 1
e_insert_excep EXCEPTION;
PRAGMA EXCEPTION_INIT(e_insert_excep, -01400);
BEGIN
INSERT INTO departments Syntax:
(department_id, department_name)
VALUES (280, NULL); exception_name EXCEPTION;
EXCEPTION
WHEN e_insert_excep
THEN
DBMS_OUTPUT.PUT_LINE('INSERT FAILED');
END;
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 21
Trapping Oracle Server Exceptions
Non-Predefined Error
DECLARE
e_insert_excep EXCEPTION;
PRAGMA EXCEPTION_INIT(e_insert_excep, -01400);
BEGIN
INSERT INTO departments 2
(department_id, department_name)
VALUES (280, NULL);
EXCEPTION
Syntax:
WHEN e_insert_excep
THEN
PRAGMA EXCEPTION_INIT(exception_name, -number);
DBMS_OUTPUT.PUT_LINE('INSERT FAILED');
END;
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 22
Trapping Oracle Server Exceptions
Non-Predefined Error
DECLARE
e_insert_excep EXCEPTION;
PRAGMA EXCEPTION_INIT(e_insert_excep, -01400);
BEGIN
INSERT INTO departments
(department_id, department_name)
VALUES (280, NULL); 3
EXCEPTION
WHEN e_insert_excep
THEN
DBMS_OUTPUT.PUT_LINE('INSERT FAILED');
END;
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 23
Trapping Oracle Server Exceptions
Functions for Trapping Exceptions
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 24
Trapping Oracle Server Exceptions
Functions for Trapping Exceptions
0 No exception encountered
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 25
Trapping Oracle Server Exceptions
Functions for Trapping Exceptions
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 26
Trapping Oracle Server Exceptions
Terminology
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 27
Trapping Oracle Server Exceptions
Summary
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 28
Trapping Oracle Server Exceptions
Summary
PLSQL S7L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 29
Trapping Oracle Server Exceptions