Home » RDBMS Server » Server Administration » Exception handlers in cursor loops
Exception handlers in cursor loops [message #370617] Sat, 08 January 2000 04:21 Go to next message
Srilatha Ramachandran
Messages: 3
Registered: January 2000
Junior Member
I am trying to use exception handler within a cursor loop for ZERO_DIVIDE error. Once the exception is raised the loop statement does not continue but I receive an error ORA-1002- fetch out of sequence. How do I continue with the loop after the exception is raised
Re: Exception handlers in cursor loops [message #370618 is a reply to message #370617] Mon, 10 January 2000 11:04 Go to previous messageGo to next message
hmg
Messages: 40
Registered: March 1999
Member
try this

set serveroutput on
declare
v_result number;
begin
for i in 1..100 loop
begin
v_result := i / mod( i, 10);
exception
when zero_divide then
dbms_output.put_line('divide by zero for i = ' || i);
end;
end loop;
end;
/
Re: Exception handlers in cursor loops [message #370621 is a reply to message #370617] Tue, 11 January 2000 07:18 Go to previous messageGo to next message
Sean Miller
Messages: 12
Registered: December 1998
Junior Member
Where is your exception?

I would expect the following to work...

FOR var IN cursor_name
LOOP
BEGIN
...code...
EXCEPTION
...exception handler...
END ;

END LOOP;

Sean
Re: Exception handlers in cursor loops [message #370625 is a reply to message #370621] Tue, 11 January 2000 10:10 Go to previous messageGo to next message
Srilatha Ramachandran
Messages: 3
Registered: January 2000
Junior Member
Thanks for your reply, i tried out the above with a while loop but does not work out

My code flows like-
--------------------------------
open c1;
LOOP
Fetch c1 into v_name,v_name1;
BEGIN
...code...
EXCEPTION
When Zero_Divide then
v_no:=0;
END ;
Insert into table1 values(v_name,v_name1,v_no);
Commit;
END LOOP;
-------------------------------------
It is at the fetch point the error occurs - fetch out of sequence.

The fetch does not get advanced to the next row in the table.
Re: Exception handlers in cursor loops [message #370630 is a reply to message #370617] Tue, 11 January 2000 23:54 Go to previous messageGo to next message
Srilatha Ramachandran
Messages: 3
Registered: January 2000
Junior Member
Yes your suggestion of using the

FOR c1 in cursor Loop
code
BEGIN

EXCEPTION ..

END
ENDLOOP

worked fine.

Thanks,
Srilatha
Re: Exception handlers in cursor loops [message #370631 is a reply to message #370621] Tue, 11 January 2000 23:57 Go to previous messageGo to next message
Srilatha
Messages: 8
Registered: January 2000
Junior Member
Yes your suggestion of using the

FOR c1 in cursor Loop
code
BEGIN

EXCEPTION ..

END
ENDLOOP

worked fine.

Thanks,
Srilatha
Re: Exception handlers in cursor loops [message #371333 is a reply to message #370617] Wed, 04 October 2000 07:00 Go to previous message
sathish kumar
Messages: 1
Registered: October 2000
Junior Member
This error occurs when the FETCH statemnet perform more then the records in the table . This error is done when the statement is written for
CURSOR FOR UPDATE,so this is happen when the fetch statement is looking for a record when the updation is over .To avoid this pls write a select statement before the cursor update the table.This may avoid reducancy and accurate.
Pls Try this and mail me if u can ......

Looking forward for ur kind attention towards my query..
Previous Topic: Another question......
Next Topic: Re: Passing arrays as parameters
Goto Forum:
  


Current Time: Sat Apr 20 06:59:49 CDT 2024