использование LISTAGG
и присоединение к подзапросу
with cte as
(
select 1 uid1 ,'testuser' as uname,'host 1' as host from DUAL union all
select 2 uid1 ,'testuser' as uname,'host 2' as host from DUAL union all
select 3 uid1 ,'testuser2' as uname,'host 3' as host from DUAL union all
select 4 uid1 ,'testuser2' as uname,'host 4' as host from DUAL
)
select cte.uname,cte.host,val from cte join (
select uname,LISTAGG(host,',') within group (order by host) as val
from cte group by uname) t on cte.uname=t.uname
dmeo link
UNAME HOST VAL
testuser host 1 host 1,host 2
testuser host 2 host 1,host 2
testuser2 host 3 host 3,host 4
testuser2 host 4 host 3,host 4