What is the simplest way to pivot Oracle columns?

The easiest way to pivot columns in Oracle is to use the UNPIVOT operator. The UNPIVOT operator can transform columns into rows. Here is an example:

SELECT *
FROM (
  SELECT id, col1, col2, col3
  FROM your_table
) 
UNPIVOT (
  value FOR column_name IN (col1, col2, col3)
);

This will pivot the “col1”, “col2”, and “col3” columns in the “your_table” table into rows. The result will include three columns: “id”, “column_name”, and “value”.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds