How to remove single quotes in Oracle PIVOT
- Alex Vincy
- Aug 26, 2018
- 1 min read
For example, below is the query to get pivot table from ORDERS table
SELECT * FROM
(
SELECT customer, product
FROM orders
)
PIVOT
(
COUNT(product)
FOR product IN ('A', 'B', 'C')
)
ORDER BY customer;
In this example, the PIVOT clause would return the following results:
customer | 'A'|'B'|'C'
---------------------------
JACK | 5 | 8 | 4
MARY | 2 | 3 | 6
WILL | 7 | 6 | 3
Now, to remove the single quotes from the heading, simply do the below change, a small change actually.
SELECT * FROM
(
SELECT customer, product
FROM orders
)
PIVOT
(
COUNT(product)
FOR product IN ('A' as "A", 'B' as "B", 'C' as "C")
)
ORDER BY customer;
So, by doing the above change, you will get exactly what you want
customer | A | B | C
---------------------------
JACK | 5 | 8 | 4
MARY | 2 | 3 | 6
WILL | 7 | 6 | 3
Comments