Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Transpose columns to rows with column header in Oracle

Have tried to convert the columns to rows in oracle but the column headers should be the first column values.

Note: The select statement with WHERE clause. Have tried PIVOT and UNPIVOT but unfortunately I am not getting the desired output.

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

It should be converted to

enter image description here

Please assist.

>Solution :

Unpivot, as you said.

Sample data:

SQL> with test (column1, column2, column3) as
  2    (select 385, 0, 29 from dual)

Query:

  3  select *
  4  from test
  5  unpivot (value for type in (column1, column2, column3));

TYPE         VALUE
------- ----------
COLUMN1        385
COLUMN2          0
COLUMN3         29

SQL>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading