If a primary stored procedure and a primary function are composed of sub-procedures or sub-functions, whether a sub-function or sub-program can contain exceptions must follow the following principles: 1. If the primary and sub-functions
If a primary stored procedure and a primary function are composed of sub-procedures or sub-functions, whether a sub-function or sub-program can contain exceptions must follow the following principles: 1. If the primary and sub-functions
If the primary stored procedure and primary function are composed of sub-procedure or sub-function, can the sub-function or sub-program contain exception handling?
Follow these principles:
1. If the main program and subprograms are to be processed as a transaction, exceptions cannot be triggered in the subprogram. exceptions must be processed in the main program. If exceptions are processed in the subprogram, if an exception occurs in the subroutine, after Exception Processing, the following code of the abnormal subroutine called in the main program will continue to be executed, and a new transaction is started, this destroys transaction consistency and data consistency.
The main program is as follows:
Procedure sp_procedure
Is
Vs_pay_year_month varchar2 (6 );
Vs_ SQL varchar2 (10000 );
Begin
Sp_procedure1;
Sp_procedure2;
Update emp set empname = 'zhang san' where empid = '000000'
Exception
WHEN OTHERS THEN
-- If an exception occurs, set the disabled trigger to valid.
Vs_ SQL: = 'alter table sal_t_mainper enable all trigger ';
Execute immediate vs_ SQL;
End;
Subroutine:
Procedure sp_procedure1
Is
Begin
Update department set dept_name = 'personnel authorization' where deptid = '201312'
Delete from department where deptid = '20140901'
Exception
WHEN OTHERS THEN
-- If an exception occurs, set the disabled trigger to valid.
Raise_application_error (-20001, 'deletion error! ');
End;
Therefore, exceptions cannot be processed in subprograms, which will damage data consistency.
Second, if the main program and subroutine are not processed as a transaction, exceptions can be triggered in the subroutine, but this situation is rare.