how about puting commit after EXIT WHEN SQL%ROWCOUNT = 0; inside the inner loop?