Oracle PL/SQL exception handling

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.