You do not need to use PL / SQL for this:
insert into my_table select score from ref r join companies c on r.total_emps on conversion_func(c.total_emps) where c.turnover > 100000
If you need to do this in the PL / SQL loop as specified, then I guarantee that you will do as little work as possible. However, I would recommend assembly instead of looping.
begin for xx in ( select conversion_func(total_emps) as tot_emp from companies where turnover > 100000 ) loop insert into my_table select score from ref where total_emps = xx.tot_emp ; end loop; end; /
For any method, you need one index at ref.total_emps
and preferably one at companies.turnover
source share