Exception error Handling

Source: Internet
Author: User

Fifth. Exception error handling

1 Exception Handling

Exception handling is used to handle unexpected events during normal execution, the exception of the block handles predefined errors and custom errors, and The program automatically terminates the entire program as soon as the PL/SQL block generates an exception and does not indicate how it should be handled

There are three types of exception errors

1 pre-defined errors

Oracle 's pre-defined exception conditions are approximately Four, and the handling of this anomaly is no longer defined in the program, with Oracle

Automatically throws it

2 non-pre-defined errors

Other standard Oracle errors, the handling of this exception requires the user to define it in the program, which is then automatically raised by Oracle

3 user-defined error

During the execution of the program, it appears that the programmer considers the abnormal situation. For this exception handling scenario, the user is required to define it in the program and then explicitly throws it in the program

Structure of exception handling:

Exception

When First_exception then workaround 1

When Second_exception then workaround 2

When others then workaround 3

End;

4 Examples of non-pre-defined exceptions

Declare

E_daleteid_exception exception;

pragma exception_inti (e_daleteid_exception,-2292); this is equivalent to encapsulating the condition of an exception trigger.

BEGIN

DELETE from employess WHERE employ_id=100;

EXCEPTION

When E_daleteid_exception then exception handling Operation

5 user-defined error examples

Declare

E_too_high_sal exception;

V_sal employees.salary&type;

Begin

Select salary into V_sal from employees where employee_id=100;

If v_sal>10000

then raise E_too_high_sal;

End if;

Exception

When E_too_high_sal and then exception handling

End;

Exception error Handling

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.