Невозможно использовать определяемые пользователем агрегатные функции в предложении Oracle PIVOT.
Я создал определяемую пользователем агрегатную функцию с именем string_agg.
Я могу использовать ее в простом выражении, например ...
select id, string_agg(value) from
(
select 'user1' as id, 'BMW' as value, 'CAR' as type from dual union
select 'user1' as id, 'Audi' as value, 'CAR' as type from dual union
select 'user2' as id, 'Honda' as value, 'CAR' as type from dual union
select 'user1' as id, 'Dell' as value, 'COMPUTER' as type from dual union
select 'user1' as id, 'Sony' as value, 'COMPUTER' as type from dual union
select 'user2' as id, 'HP' as value, 'COMPUTER' as type from dual
)
group by id, type
Результат:
<b>ID TYPE STRING_AGG(VALUE)</b>
user1 CAR Audi,BMW
user1 COMPUTER Dell,Sony
user2 CAR Honda
user2 COMPUTER HP
Однако, когда я пытаюсь использовать ту же функцию в предложении сводки
select * from
(
select id, type, string_agg(value) as value from
(
select 'user1' as id, 'BMW' as value, 'CAR' as type from dual union
select 'user1' as id, 'Audi' as value, 'CAR' as type from dual union
select 'user2' as id, 'Honda' as value, 'CAR' as type from dual union
select 'user1' as id, 'Dell' as value, 'COMPUTER' as type from dual union
select 'user1' as id, 'Sony' as value, 'COMPUTER' as type from dual union
select 'user2' as id, 'HP' as value, 'COMPUTER' as type from dual
)
group by id, type
)
PIVOT (string_agg(value) FOR id IN ('user1' user1, 'user2' user2) );
, я получаю следующую ошибку ...
ORA-56902: expect aggregate function inside pivot operation<br>
Ожидаемый результат ... ... 1017 *
<b>TYPE USER1 USER2</b>
COMPUTER Dell,Sony HP
CAR Audi,BMW Honda