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