Results 1 to 6 of 6

Thread: PL/SQL Question

  1. #1
    Expert Member
    Join Date
    Oct 2006
    Answers
    209

    PL/SQL Question

    Hi, I m a beginner, pls how can I exit this Loop.

    LOOP
    update Table1 set name = 'xxx'
    where number LIKE '1%';
    END LOOP;

    I want to update some rows and exit this loop when all rows are updated.

    Thanks


  2. #2
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    Re: PL/SQL Question

    the follow is the syntax for loop

    LOOP
    ;
    EXIT WHEN
    ;
    END LOOP;

    u just need to add exit when with some condition


    But tell me first to update why need a loop. while u can do the same by a simple DML ???


  3. #3
    Junior Member
    Join Date
    Jul 2007
    Answers
    1

    Thumbs up Re: PL/SQL Question

    Quote Originally Posted by JobHelper View Post
    Hi, I m a beginner, pls how can I exit this Loop.

    LOOP
    update Table1 set name = 'xxx'
    where number LIKE '1%';
    END LOOP;

    I want to update some rows and exit this loop when all rows are updated.

    Thanks
    use :
    my question is why you want loop concept ? ,just update the '1%' records.
    whether you want other purpose means use

    declare
    n number;
    i number default 1;
    begin
    select count(*) from table1 where number like '1%';
    loop
    update Table1 set name = 'xxx' where number LIKE '1%';
    i=:i+1;
    exit when i>=n
    end;


    by Sekar.S


  4. #4
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    Re: PL/SQL Question

    loop is used to repeatedly execute a certain statment till a certain condition is acchieved.


  5. #5

    Re: PL/SQL Question

    U can use cursors more effectively for this purpose.U can use %notfound attribute of cursor to break the loop like
    loop
    update...
    exit when cursorname%notfound
    end loop;


  6. #6
    Junior Member
    Join Date
    Jun 2007
    Answers
    18

    Re: PL/SQL Question

    use this condition
    EXIT WHEN SQL%NOTFOUND


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact