As per oracle documentation, PIVOT
function doesn't support sub-query in the "IN
" clause but it is possible in the PIVOT
XML function.
E.g.
SELECT *
FROM table_name
PIVOT
(
SUM(column_name_1)
FOR [column_name_2] IN (['Output_Column1'],['Output_Column2'])
)
AS aliasName
I need to replace the ['Output_Column1'],['Output_Column2']
with sub-query.
Is there some other function equivalent to PIVOT
where we can supply sub-query instead hard coding the entire output columns or even in the PIVOT
function itself?.
No, the number of columns must be known at parse time. For PIVOT XML there is no problem because such query returns only one column.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With