PL/SQL daily question: Exception Handling-When clause

Source: Internet
Author: User

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

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.