How can one achieve pivot columns into rows in Oracle?
In Oracle database, you can use the UNPIVOT operation to convert columns into rows. Here is an example:
Assume there is the following table t1:
To convert columns into rows, you can use the UNPIVOT operation as shown below:
SELECT *
FROM t1
UNPIVOT (Value FOR Attribute IN (Name, Age, City))
After running the above query, the following results will be obtained:
By using the UNPIVOT operation, every original row is transformed into multiple rows, with each row containing the ID, attribute, and value of the original row.