Wat is hier de noodzaak van een lus? U moet uw update-statement herschrijven naar iets als dit:
UPDATE t_numbers tn
SET tn.country = (SELECT ic.country
FROM int_codes ic
WHERE ic.int_code = substr(tn.phone_number, 1, 4))
WHERE tn.country is null
AND EXISTS (SELECT 1
FROM int_codes ic
WHERE ic.int_code = substr(tn.phone_number, 1, 4));
Herhaal dan hetzelfde voor 3, 2 en 1 als volgt (voor 3):
UPDATE t_numbers tn
SET tn.country = (SELECT ic.country
FROM int_codes ic
WHERE ic.int_code = substr(tn.phone_number, 1, 3))
WHERE tn.country is null
AND EXISTS (SELECT 1
FROM int_codes ic
WHERE ic.int_code = substr(tn.phone_number, 1, 3));
UPDATE:
Je kunt ook 4 naar 1 doorlopen om de taak te volbrengen
begin
for i in 1..4 loop
UPDATE t_numbers tn
SET tn.country = (SELECT ic.country
FROM int_codes ic
WHERE ic.int_code = substr(tn.phone_number, 1, (5-i)))
WHERE tn.country is null
AND EXISTS (SELECT 1
FROM int_codes ic
WHERE ic.int_code = substr(tn.phone_number, 1, (5-i)));
end loop;
END;