Home » SQL & PL/SQL » SQL & PL/SQL » EXCEPTION inside FOR..LOOP
EXCEPTION inside FOR..LOOP [message #9965] Wed, 17 December 2003 18:43 Go to next message
resy
Messages: 86
Registered: December 2003
Member
HI,

declare
cursor c1 is
select sid,scity
from supplier;
wrong_city exception;
begin
for s_rec in c1 loop
if s_rec.scity = 'bangalore' then
raise wrong_city;
end if;
end loop;
exception
when wrong_city then
dbms_output.put_line('wrong city');
end;

result:

SQL> /
wrong city

PL/SQL procedure successfully completed.

Here in my table 'SUPPLIER' i've more than 1 record which has the value 'BANGALORE'. But this code ends as sson as it got one record with the value 'BANGALORE'.
I want continue the loop until all the records are checking.
How can i go back to that FOR ..LOOP after fetching and displaying the exception?

can anybody give me the solution?

thanx .
Re: EXCEPTION inside FOR..LOOP [message #9966 is a reply to message #9965] Wed, 17 December 2003 20:33 Go to previous messageGo to next message
Rajarshi Dasgupta
Messages: 52
Registered: October 2001
Member
do it this way...

declare
cursor c1 is
select sid,scity
from supplier;
wrong_city exception;
begin
for s_rec in c1 loop
begin
if s_rec.scity = 'bangalore' then
raise wrong_city;
end if;
exception
when wrong_city then
dbms_output.put_line('wrong city');
end;
end loop;
end;
Re: EXCEPTION inside FOR..LOOP [message #9967 is a reply to message #9966] Wed, 17 December 2003 21:40 Go to previous message
resy
Messages: 86
Registered: December 2003
Member
thanQ
Previous Topic: how to perform DML on D2K block based on Views
Next Topic: Defferene b/w schema and database users
Goto Forum:
  


Current Time: Wed Apr 17 21:56:35 CDT 2024