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?
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?
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
.
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;