serdar serdar - 4 months ago 19
SQL Question

Oracle show columns as row

How can i convert multiple column to row accoding by followed sample? For solution, i inspected many sample for example pivot, decode etc. but i did not reach absolute solution.

+---------+---------+---------+---------+
| COL_1 | COL_2 | COL_3 | COL_4 |
+---------+---------+---------+---------+

I wanna make columns like this;

+---------+
| COL_1 |
+---------+
| COL_2 |
+---------+
| COL_3 |
+---------+
| COL_4 |
+---------+

Answer

Maybe you wanted unpivot?

with demo as ( select 1 as col1, 2 as col2, 3 as col3, 4 as col4 from dual )
select * from demo
unpivot
( colvalue for col in (col1, col2, col3, col4) );

COL    COLVALUE
---- ----------
COL1          1
COL2          2
COL3          3
COL4          4

4 rows selected.
Comments