You never decrement rowcount
so you will end up deleting the rows in temp_display
one-by-one and then keep going (potentially forever) and on the next iteration after you have already emptied the table you will try to select id_barang into id_brg ...
and it will fail as you have already emptied the table.
Instead, you could use BULK COLLECT INTO
or a CURSOR
to bypass the temporary table:
create or replace procedure check_display_stock
as
begin
FOR cur IN ( select id_barang,
stok,
min_stok
from display
where stok <= min_stok
)
LOOP
insert_spb(cur.id_barang);
END LOOP;
END;
/
db<>fiddle here
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…