If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > Exception handling continue loop with out break

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-26-10, 04:23
scharan07 scharan07 is offline
Registered User
 
Join Date: Jul 2009
Location: Mumbai
Posts: 21
Exception handling continue loop with out break

Hi,

I have written a procedure, in which i have cursor, looping through the cursor,
i want to handle exception in this loop such way that it should continue with the next iteration not to break out the loop.
Reply With Quote
  #2 (permalink)  
Old 08-26-10, 06:53
magicwand magicwand is offline
Registered User
 
Join Date: Mar 2010
Location: Vienna, Austria
Posts: 111
That's how to do it (in this example, a divide by zero - exception is caught):

Code:
begin
  for i in 1..10 loop
    begin
       dbms_output.put_line('i | i / (i - 5):' || i || '|' || i / (i - 5));
    exception
       when ZERO_DIVIDE then dbms_output.put_line ('This Line from exception handler') ;continue;
       when others      then dbms_output.put_line('Error: ' || SQLCODE || ' ' || SQLERRM); exit;
    end;
  end loop;
end;
/

Output:
Code:
i | i / (i - 5):1|-,25
i | i / (i - 5):2|-,6666666666666666666666666666666666666667
i | i / (i - 5):3|-1,5
i | i / (i - 5):4|-4
This Line from exception handler
i | i / (i - 5):6|6
i | i / (i - 5):7|3,5
i | i / (i - 5):8|2,66666666666666666666666666666666666667
i | i / (i - 5):9|2,25
i | i / (i - 5):10|2
__________________
If A is a success in life, then A = x + y + z.
Work is x; y is play; and z is keeping your mouth shut. After all the years, I'm still working on the correct value for z.
(Albert Einstein)

Last edited by magicwand; 08-26-10 at 06:57. Reason: typo fixed
Reply With Quote
  #3 (permalink)  
Old 08-27-10, 02:46
scharan07 scharan07 is offline
Registered User
 
Join Date: Jul 2009
Location: Mumbai
Posts: 21
i am using 10g continue statement is giving error.
Quote:
"PLS-00201: identifier 'CONTINUE' must be declared"
My code goes like this

Code:
begin
<expressions>
exception
when others  then 
dbms_output.put_line('Error: ' || SQLCODE); 
continue;
END;
Reply With Quote
  #4 (permalink)  
Old 08-27-10, 10:08
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,153
>i am using 10g continue statement is giving error.

Please post URL to documentation for said "CONTINUE" statement.
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #5 (permalink)  
Old 08-27-10, 18:27
magicwand magicwand is offline
Registered User
 
Join Date: Mar 2010
Location: Vienna, Austria
Posts: 111
scharan07,

you can simply omit the CONTINUE in 10g (in 11g CONTINUE just starts the next loop of the iteration).

The important thing is, to handle the exception in a block within the loop.

anacedent,

CONTINUE Statement
__________________
If A is a success in life, then A = x + y + z.
Work is x; y is play; and z is keeping your mouth shut. After all the years, I'm still working on the correct value for z.
(Albert Einstein)

Last edited by magicwand; 08-27-10 at 18:56.
Reply With Quote
  #6 (permalink)  
Old 08-30-10, 04:30
scharan07 scharan07 is offline
Registered User
 
Join Date: Jul 2009
Location: Mumbai
Posts: 21
Cool

So it is newly introduced in 11g.
In 10g it auto do's with out continue statement.

Thanks for you replies magicwand
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On