top of page

How to remove single quotes in Oracle PIVOT

  • Writer: Alex Vincy
    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

 
 
 

Recent Posts

See All
QR and Barcode Scanner

Click here to get the most powerful QR and barcode scanner. Fast & Accurate QR barcode scanner. Scans all QR and Barcode formats. Simple...

 
 
 
Oracle Pivot Example

Occasionally it may be necessary to 'flip' a table on its side, so to speak, meaning to convert rows to columns in order to display data...

 
 
 

Comments


© 2023 by Money Savvy. Proudly created with wix.com

Get Social

  • Grey Facebook Icon
  • Grey Twitter Icon
  • Grey Google+ Icon
  • Grey LinkedIn Icon
  • Grey YouTube Icon
bottom of page