Ниже представлены результаты тестовых данных, которые вы предоставили. Запрос такой же, как у вас, и я добавил условие NVL в условии соединения, так как были нулевые номера телефонов.
with t1 as
(
select '+271566681' as telephone1, null as telephone2 from dual
union
select '+276445884' as telephone1, '+271679161' as telephone2 from dual
union
select '+275684835' as telephone1, NULL as telephone2 from dual
union
select NULL as telephone1, '+276496136' as telephone2 from dual
)
,t2 as
(
select 'MTN' as opetr, '+2764' as rnge from dual
union
select 'Vodacom' as opetr, '+2716' as rnge from dual
)
select
t1.telephone1, t22.opetr,
t1.telephone2, t23.opetr
from t1
left outer join t2 t22 on substr(nvl(t1.telephone1, '00000'),1,5) = t22.rnge
left outer join t2 t23 on substr(nvl(t1.telephone2, '00000'),1,5) = t23.rnge;
NULL NULL +276496136 MTN
+276445884 MTN +271679161 Vodacom
+271566681 NULL NULL NULL
+275684835 NULL NULL NULL
Your query would be -
select
t1.telephone1, t22.operator,
t1.telephone2, t23.operator
from Contacts t1
left outer join tFormat t22 on substr(nvl(t1.telephone1, '00000'),1,5) = t22.range
left outer join tFormat t23 on substr(nvl(t1.telephone2, '00000'),1,5) = t23.range;
Note - There are issue with the test data which you have provided
> Table has 4 records but output has 3 records
> we don't have telephone1 number starting with +2716, but your output has one
> There is record in output which starts with ++, which is not there in your test data.