11g PIVOT uses static columns - why why why???
952727Jul 30 2012 — edited Aug 14 2012I am very curios to know why we have to hard-code the "pivot in" clause in a pivot query. Does this not defeat the purpose of pivoting?
we have to write this:
SELECT *
FROM (SELECT customer_id, product_code, quantity
FROM pivot_test)
PIVOT (SUM(quantity) AS sum_quantity FOR (product_code) IN ('A' AS a, 'B' AS b, 'C' AS c))
ORDER BY customer_id;
Why can we not put a subquery in the "IN" clause? Or even better, leave it blank to indicate we are pivoting for all.
I know you can do something like this with the PIVOT XML function, but I want columns in the result, not XML. And I also do not want to build the query as a string and execute it like that, it gets really messy and I feel sorry for the next bloke who needs to take over from me.
Does anybody know why this seems to not be possible for ORACLE?
Thanks all.