Click to See Complete Forum and Search --> : Go to Next Record in For Loop


lesstjm
06-09-2003, 01:28 PM
I want to know how to go to the next record in a for loop if a column in a record equals a certain value. For example


declare

cursor c1 is
select * from mytable;

begin

for v1 inc1 loop

if v1.mycolumn = 'A' then

< here is where I want to tell it to go to the next record >

end if;


v1.mycolumn = 'R';

end loop;
end;
/

Can I use some type of break command.

stecal
06-09-2003, 02:01 PM
Forms? next_record

You could also do null (if a=b then null) to do nothing (assuming nothing else is processed). You could use goto, but that isn't usually recommended. You could use WHILE instead of what you have now.

When you want to go to the next record, while using a loop, let the loop control structure call the next record for you. So in your example, do nothing ("null;").

select * for a cursor - do you really need to select every column from a table? That is lazy. And what happens when a=b? Do you need to stop the loop, or continue to evaluate each record?

marist89
06-09-2003, 02:08 PM
I guess I'm missing the point here, but why not:


DECLARE

CURSOR c1 IS
SELECT * FROM mytable
WHERE myColumn <> 'A'