select a_id,... from
( select a_id,b_id,... from
(select a.rownum as a_id,... from a ) as A1,
(select b.rownum as b_id,... from a ) as B1
where A1.a_id = B1.b_id(+)
)
union all
select b_id,... from
( select a_id,b_id,... from
(select a.rownum as a_id,... from a ) as A1,
(select b.rownum as b_id,... from a ) as B1
where B1.b_id = A1.a_id(+)
and not exists
( select 1 from
( select a_id,b_id,... from
(select a.rownum as a_id,... from a ) as A1,
(select b.rownum as b_id,... from a ) as B1
where A1.a_id = B1.b_id(+)
) XX where XX.a_id = B1.b_id
)
)