Execute sql query in loop
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: Execute sql query in loop

  1. #1
    Join Date
    Sep 2007
    Posts
    2

    Execute sql query in loop

    Hi guys,

    I am trying to execute the following statement in Oracle isql*plus, but i am getting error message. Could anyone help?

    declare
    i varchar(200);

    begin
    for a in 1 .. 10 loop
    i := 'select count(*) from messages';
    dbms_output.put_line (i);
    a := a + 1;
    end loop;

    END;

    All I would like to do is to run the statement of "select count(*) from messages" in every second, so I was trying to do it in for loop so that I don't need to click execute button in every second.

    Thanks

  2. #2
    Join Date
    Nov 2000
    Location
    Pittsburgh, PA
    Posts
    4,027

    Question

    "a" is the index variable in a for loop and should not get manually incremented. If left alone it will increment itself. You don't state the error message, but without running the code I'm guessing that that is it. You are also seemingly trying to print out the same query 10 times without changing it. What are you really trying to do, and what error are you getting?

    declare
    i varchar(200);

    begin
    for a in 1 .. 10 loop
    i := 'select count(*) from messages';
    dbms_output.put_line (i);
    a := a + 1;
    end loop;

    END;
    this space intentionally left blank

  3. #3
    Join Date
    Sep 2007
    Posts
    2
    All I want to do is to get the result of

    select count(*) from messages

    in every second, instead of keep typing such query.

    Thanks.

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