Hi I have a table test its structure is given below:
**Testing**
PK C1 c2
---------------
1 v11 v12
2 v21 v23
3 v31 v32
No, it can't be done with PIVOT
, but it can be done with UNPIVOT:
SELECT
Pk,
"Key",
value
FROM Testing
UNPIVOT (
value FOR "Key" IN (C1, C2)
)
And when UNPIVOT
is unavailable, I often unpivot like this:
SELECT
t.Pk,
x."Key",
CASE x."Key"
WHEN 'C1' THEN t.C1
WHEN 'C2' THEN t.C2
END AS value
FROM Testing t
CROSS JOIN (
SELECT 'C1' AS "Key" FROM DUAL UNION ALL
SELECT 'C2' FROM DUAL
) x