PLSQL know the amount of records inside a "for cursor"

2

Inside the example below:

Begin
  For r in (select * from tabela)
  Loop
    ..... ;
  End loop;
End;

Is there any direct way to know within the loop how many records the cursor has?

    
asked by anonymous 23.08.2014 / 13:13

2 answers

3

Try this:

BEGIN
  FOR r IN (SELECT COUNT(*) OVER() total_de_registros
                  ,t.*
              FROM tabela t)
  LOOP
    .. .. .;
  END LOOP;
END;

In the above example, the COUNT(*) OVER() clause counts all records that return in the query without the need to add a group by .

    
10.03.2015 / 18:35
1

I do not know if that's the idea.

But it can be done that way.

declare
vtabela tabela%rowtype;
Begin
  select t.* into vtabela from tabela;
  For r in 1..vtabela.count loop
  Loop
    ..... ;
  End loop;
End;
    
03.09.2014 / 23:57