A preliminary study on the mechanism of abnormal handling of pl/sql

Source: Internet
Author: User

How to continue after an exception is thrown in Pl/sql

This question once let me depressed, very useful skill!

sql> Declare
2 type TESTITB is table of number index by Binary_integer;
a testitb;
b number;
3 4 5 begin
A: =11
6 7 A (1): =12
A (4): =4;
8 9
for I a.first. A.last loop
B:=i;
Dbms_output.put_line (' a= ' | | A (i));
End Loop;
EXCEPTION
When No_data_found THEN
dbms_output.put_line (' b= ' | | b);
End;
/
a=12
b=2
In this case, when a (2) throws a No_data_found exception, the entire block exits. Modify the exception position and place it in the loop.
Declare
Type TESTITB is table of number index by Binary_integer;
a TESTITB;
B number;
Begin
A: =11
A (1): =12
A (4): =4;
for I in A.first. A.last loop
begin
B:=i;
DBMS_OUTP Ut.put_line (' a= ' | | A (i));
EXCEPTION
When No_data_found THEN
dbms_output.put_line (' b= ' | | b);
End;
End Loop;
End;
/
a=12
b=2
b=3
a=4
b=5
b=6
b=7
b=8
b=9
a=11

Pl/sql procedure successfully completed.

This way it can be done without affecting the entire pl/sql block.

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.