Oracle database - get two rows (A,B) for every (COD) row
I solve it with UNION ALL:

with cte as
        (select rap.cod,
                case
                 when (coalesce(val1_a.v1,0)&lt;&gt;0 or
                       coalesce(val1_a.v2,0)&lt;&gt;0 or
                       coalesce(val1_a.v3,0)&lt;&gt;0)
                 then
                    'A'
                end
                 as cat,
               coalesce(val1_a.v1,0) as v1_a,
               coalesce(val1_a.v2,0) as v2_a,
               coalesce(val1_a.v3,0) as v3_a,
               coalesce(val1_b.v1,0) as v1_b,
               coalesce(val1_b.v2,0) as v2_b,
               coalesce(val1_b.v3,0) as v3_b
         from rap
             full outer join val1_a on val1_a.fk_rap=rap.id
             full outer join val1_b on val1_b.fk_rap=rap.id
         UNION ALL
         select rap.cod,
                case
                 when (coalesce(val1_b.v1,0)&lt;&gt;0 or
                       coalesce(val1_b.v2,0)&lt;&gt;0 or
                       coalesce(val1_b.v3,0)&lt;&gt;0)
                 then
                    'B'
                end
                 as cat,
               coalesce(val1_a.v1,0) as v1_a,
               coalesce(val1_a.v2,0) as v2_a,
               coalesce(val1_a.v3,0) as v3_a,
               coalesce(val1_b.v1,0) as v1_b,
               coalesce(val1_b.v2,0) as v2_b,
               coalesce(val1_b.v3,0) as v3_b
         from rap
             full outer join val1_a on val1_a.fk_rap=rap.id
             full outer join val1_b on val1_b.fk_rap=rap.id
       )
 select cod,
        cat,
        case when cat='A' then v1_a
             when cat='B' then v1_b
        end
          as v1,
        case when cat='A' then v2_a
             when cat='B' then v2_b
        end
          as v2,
        case when cat='A' then v3_a
             when cat='B' then v3_b
        end
          as v3
 from cte