Alternative Method for PIVOT - IN with Subquery Support

According to oracle documentation, a function PIVOTdoes not support a subquery in a sentence IN, but it is possible in an PIVOTXML function . For instance.

SELECT *
FROM table_name
PIVOT
(
  SUM(column_name_1)
  FOR [column_name_2] IN (['Output_Column1'],['Output_Column2'])
)
AS aliasName

I need to replace ['Output_Column1'],['Output_Column2']with a subquery.

Is there any other function equivalent PIVOTwhere we can put a subquery instead of hard-coding all output columns or even the function itself PIVOT?

+5
source share
1 answer

No, the number of columns should be known during parsing. There is no problem for PIVOT XML because such a query returns only one column.

+1
source

All Articles