How to reference loop index i in SP?

General
Enthusiast

How to reference loop index i in SP?

Hi please help on below question:

Table2 has structureas

v_1, v_2, v_3

each time I only want to select one variable so want to reference loop index i in a stored procedure. Is this possible in TD? Many thanks!

++++++++++++++++++++++

replace procedure abc();

begin;

    declare i integer default 0;

    loopi: loop

         set i = i + 1;

             if i > 10 then leave loopi;

             end if;

             insert into table1 

             select * from table2

             where v_i = 1;

   end loop loopi;

end;