Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to write loop in pl/sql that goes over numbers

Tags:

sql

oracle

plsql

I want to write a loop that iterates over numbers 105 102 19 17 101 16 106 107

for each iteration I want to plug the number in a query and insert it into a table.

pseudo:

LOOP (105 102 19 17 101 16 106 107)
   FETCH select * from some_table where value=current_iteration_index --105..etc.
   INTO my_rec_type

END LOOP;
like image 303
learn_plsql Avatar asked Nov 30 '22 10:11

learn_plsql


1 Answers

Another method:

declare
 type numListType is table of number;
 numList numListType;
begin
numList := numListType(
 105,102,19,17,101,16,106,107 
);
for i in numList.FIRST..numList.LAST loop
 -- your usage of element goes here
 dbms_output.put_line(numList(i));
end loop;
end;
/
like image 179
dpbradley Avatar answered Dec 04 '22 07:12

dpbradley