EXCEPTION inside FOR..LOOP [message #9965] |
Wed, 17 December 2003 18:43 |
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 |
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;
|
|
|
|