В Oracle 11.1 и выше вы можете использовать оператор PIVOT
.Предполагая, что имя таблицы T
:
select id, horse, dog, duck
from t
pivot (min(value_2)
for value_1 in ('HORSE' as horse, 'DOG' as dog, 'DUCK' as duck))
order by id
;
В Oracle 12.1 и выше, того же можно достичь с помощью MATCH_RECOGNIZE
(и нам больше не нужна агрегация):
select id, horse, dog, duck
from t
match_recognize(
partition by id
measures horse.value_2 as horse,
dog.value_2 as dog,
duck.value_2 as duck
pattern ( (horse|dog|duck)* )
define horse as value_1 = 'HORSE', dog as value_1 = 'DOG',
duck as value_1 = 'DUCK'
);