3 Replies Latest reply: Dec 4, 2012 1:40 PM by 976563 RSS

    PL/SQL Help

    976563
      I have a table with a column that contains a number (1-10). I want to extract data from the table for each set 1-10...lets say 10-25 rows. Instead of running the same SQL statement 10 times for each number, I wanted to incorporate a loop, but am having trouble with it. After the results are generated, I would like to just export it to like an .xls file. This is what I have that does not work...any help would be great. Thanks.

      ------

      BEGIN

      FOR i IN 1 .. 3
      LOOP

      SELECT * FROM table1 WHERE column1 = i AND ROWNUM <= 10;

      END LOOP;
      END;
        • 1. Re: PL/SQL Help
          kikolus
          Hi,
          I'm not sure what about your expected result, but you can do something like that:
           
          with d as (select 'a' cold from dual 
                     union 
                     select 'b' cold from dual 
                     ) 
          select * from d, (select * from dual connect by level <10) 
          where cold = 'a' 
          regards
          kikolus
          • 2. Re: PL/SQL Help
            Marwim
            Hello,

            welcome to the forum.

            This is the forum for the Oracle Developer tool named Reports. Your query should be asked in {forum:id=75}.
            Please read the FAQ, especially {message:id=9360002} and {message:id=9360007} before posting there.

            Regards
            Marcus
            • 3. Re: PL/SQL Help
              976563
              Thanks, I will try it out and see what happens.

              Sorry, Marcus, I will be more careful next time.