Home » SQL & PL/SQL » SQL & PL/SQL » Horizontal to Vertical Transpose. (Oracle 10g; Windows)
Horizontal to Vertical Transpose. [message #397744] |
Mon, 13 April 2009 13:43  |
Nirmala
Messages: 43 Registered: October 2004
|
Member |
|
|
I have a table which has 12 columns. For every row in that table i want the output to be spilt into 12 rows.
create table monthly
(jan number(10),
feb number(10),
mar number(10),
apr number(10),
may number(10),
jun number(10),
jul number(10),
aug number(10),
sep number(10),
oct number(10),
nov number(10),
dec number(10));
insert
into monthly
values (1000,
1000,
1000,
1000,
1000,
1000,
1000,
1000,
1000,
1000,
1000,
1000);
I want the output from this table as 12 rows as given below. Is there anyway i can get it using a SQL Query?
Jan 1000
Feb 1000
Mar 1000
Apr 1000
May 1000
Jun 1000
Jul 1000
Aug 1000
Sep 1000
Oct 1000
Nov 1000
Dec 1000
|
|
|
|
|
Re: Horizontal to Vertical Transpose. [message #398523 is a reply to message #397744] |
Thu, 16 April 2009 09:19   |
yugi.adapala
Messages: 10 Registered: April 2009
|
Junior Member |
|
|
SELECT decode(row_num,
1,
'jan',
2,
'feb',
3,
'mar',
4,
'apr',
5,
'may',
6,
'jun',
7,
'jul',
8,
'aug',
9,
'sep',
10,
'oct',
11,
'nov',
12,
'dec') mon,
decode(row_num,
1,
jan,
2,
feb,
3,
mar,
4,
apr,
5,
may,
6,
jun,
7,
jul,
8,
aug,
9,
sep,
10,
oct,
11,
nov,
12,
DEC) val
FROM (SELECT m.ROWID row_id, m.* FROM monthly m) mon,
(SELECT rownum row_num FROM dual CONNECT BY LEVEL <= 12);
|
|
|
|
Goto Forum:
Current Time: Sun Aug 24 02:32:18 CDT 2025
|