Question:
Catch an error with Zero Divisor ("ORA-01476: divisor is equal to zero") and show "bad division" in this case"
All other exceptions must be transmitted to the call block intact.
In other words, if I add the following exception handling section and then execute the followingCodeBlock:
Begin plch_proc (0); plch_proc (-1); Exception when others then dbms_output.put_line ('all handled '); end ;/
Then I should see the following output on the screen:
Bad Division
All handled
(A) exception when 'ora-01476 'Then dbms_output.put_line ('bad division'); (B) exception when zero_divide then dbms_output.put_line ('bad division '); (c) exception when others then if sqlcode =-01476 then dbms_output.put_line ('bad division '); else raise; end if; (d) exception when others then if sqlcode = 1476 then dbms_output.put_line ('bad division '); end if; (e) exception when others then if sqlcode =-1476 then dbms_output.put_line ('bad division '); end if;
Answer:
Select: BC
A: syntax error. When must follow the defined exception, which can be system-defined or custom.
B: zero_divide is a system definition exception.
C: When others is used to capture all exceptions and process one of the error codes, the others will continue to be thrown, so other exceptions can be caught at the upper layer.
D: The error code is incorrectly written.
Sqlcode generally returns a negative number to handle these situations:
① No exception (0 is returned)
② Custom exceptions are not associated with an error code with exception_init.
At this time, 1 user-defined exception is returned and the exception_init is not used to associate with an error code (1 is returned at this time)
③ No_data_found (sqlcode returns 100)
E: the difference with C is that raise is not used to continue to throw, so the upper layer cannot capture