创建表T,结构与数据如下:
SQL> desc t
Name
Null?Type
----------------------------------------- -------- ----------------------------
ID
NUMBER
NAME
VARCHAR2(2)
SQL> select *
2from t
3/
ID NAME
---------- ----
2 b
2 b1
3 c
1 a
1 a1
3 c1
6 rows selected.
SQL>
可以使用以下SQL,这个SQL勉强可以用,呵呵。。
SQL> column x format a5
SQL> column y format a5
SQL> column z format a5
SQL> select decode(rownum,2,translate(x,1,' '),x) x,
2 decode(rownum,2,translate(y,1,' '),y) y,
3 decode(rownum,2,translate(z,1,' '),z) z
4from(
5 select r,max(
6
case when id = 1 and r = 1
7
then to_char(id)
8
when id = 1 and r = 2
9
then name
10
when id = 1 and r = 3
11
then name
12
end) x,
13
max(
14
case when id = 2 and r = 1
15
then to_char(id)
16
when id = 2 and r = 2
17
then name
18
when id = 3 and r = 3
19
then name
20
end) y,
21
max(
22
case when id = 3 and r = 1
23
then to_char(id)
24
when id = 3 and r = 2
25
then name
26
when id = 3 and r = 3
27
then name
28
end) z
29 from t,(select level r from dual connect by rownum
|