Search code examples
sqloracle-databasepivotunpivot

Use of pivot function


I have the following oracle table:

Tag  Value
A    Test
B    Test2 
C    Test3
D    Test4

But need an output like:

A    B     C     D 
Test Test2 Test3 Test4

Where A, B, ... should be my column names. I know the pivot/unpivot function but I didn't get the right result yet.

This was my attempt but with no succes because of error: ORA-00933

SELECT *
FROM (
  SELECT tag
  FROM table
  WHERE VALUES LIKE '%Test%'
 ) AS DT
 PIVOT(max(value) FOR tag IN([A],[B])) AS PT

Solution

  • Something like that:

    select * from (select tag, Value from TAB) PIVOT (max(value) for tag in ('A','B','C','D'))