Exceptions in Oracle database: no exception is transferred because there is no distinction between a inspected exception and a non-inspected exception.
1. The generation of exceptions:
2. Handling of Exceptions:
Declare
--Variable definition, initialization assignment.
Begin
--Assignment of variables, function calls, if,while and so on.
exception
--Exception handling code
When the others then exception-handling statement.
End
3. Exception Throw: Raise
4. Multiple exception handling: Java's multiple exceptions are differentiated by data types, and multiple exceptions to Oracle databases are distinguished by exception numbers.
Distinguishing between different exceptions is the precondition of implementing multiple exception handling.
Declare
Verror exception;--Defining exception variables
PRAGMA Exception_init (Verror,-111111);--Set the number of the exception variable
Begin
--Assignment of variables, function calls, if,while and so on.
exception
When the verror then exception-handling statement. --The number of the exception variable being thrown is the same as the number of the set exception variable.
When the others then exception-handling statement. --Executes the statement (written at the end) when the exception number that is thrown does not exist in the exception statement block.
End
5. Custom exception: implemented by defining a new Exception class in Java. Implemented by exception numbers in Oracle.
1 Eclare2N Number (1);3 V_error exception;4 begin5Dbms_output.put_line (' Throw a single exception practice--n only 1 bits cannot save the number 10 ');6n:=10;7 ifN<=0 Then8 raise V_error;9Endif;Ten dbms_output.put_line (n); One Exception AWhen others then Dbms_output.put_line (' Value overflow '); - end; - the Declare -N Number (1); - V_error exception; -PRAGMA Exception_init (v_error,-112122); + begin -Dbms_output.put_line (' Throw multiple exception exercises '); +N:=-1; A ifN<=0 Then at raise V_error; -Endif; - dbms_output.put_line (n); - Exception -When the v_error then Dbms_output.put_line (' can't be negative '); -When others then Dbms_output.put_line (' Value overflow '); inEnd