DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: Go to Next Record in For Loop

  1. #1
    Join Date
    Jan 2001
    Posts
    515

    Question Go to Next Record in For Loop

    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.

  2. #2
    Join Date
    May 2002
    Posts
    2,645
    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?
    Last edited by stecal; 06-09-2003 at 02:10 PM.

  3. #3
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    I guess I'm missing the point here, but why not:

    Code:
    DECLARE
    
       CURSOR c1 IS
          SELECT * FROM mytable
          WHERE myColumn <> 'A'
    Jeff Hunter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width