Jornia Kabakum Jornia Kabakum - 1 month ago 10
SQL Question

One row with multiple columns to two columns per row

I am having trouble creating a SQL select in Oracle, which does the following.

I have a

table (col1, col2 ... col15)


with 15 columns per row.

How can I make query as follows:

row1: col1, col2
row2: col3, col4
row3: col5, col6

...
rowN: col14, col15

Answer

Assuming all columns are of the same datatype, you could do a union. It will be tedious.

SELECT COL1, COL2 FROM TABLE_1
UNION ALL
SELECT COL3, COL4 FROM TABLE_1
UNION ALL
......
SELECT COL13, COL14 FROM TABLE_1

If you tell me your a little more about the problem maybe it can be solved in some way other than a plain query?

For example - if you are using another programing language perl or php, you can select row wise and output 8 lines per row.

Or, if its pure database, you can consider PL/SQL.