ID |
MON |
A |
B |
C |
D |
E |
F |
AA |
01 |
43 |
11 |
||||
AA |
02 |
22 |
32 |
||||
BB |
01 |
12 |
52 |
63 |
|||
BB |
02 |
23 |
65 |
32 |
|||
BB |
03 |
11 |
32 |
5 |
ID |
MON |
CODE |
VAL |
AA |
01 |
A |
43 |
AA |
01 |
B |
11 |
AA |
02 |
A |
22 |
AA |
02 |
B |
32 |
BB |
01 |
A |
12 |
BB |
01 |
B |
52 |
BB |
01 |
C |
63 |
BB |
02 |
A |
23 |
BB |
02 |
B |
65 |
BB |
02 |
C |
32 |
BB |
03 |
A |
11 |
BB |
03 |
B |
32 |
BB |
03 |
C |
5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | WITH t(id, mon, a, b, c, d, e, f) AS ( SELECT 'AA' , '01' , 43, 11, null , null , null , null FROM dual UNION ALL SELECT 'AA' , '02' , 22, 32, null , null , null , null FROM dual UNION ALL SELECT 'BB' , '01' , 12, 52, 63, null , null , null FROM dual UNION ALL SELECT 'BB' , '02' , 23, 65, 32, null , null , null FROM dual UNION ALL SELECT 'BB' , '03' , 11, 32, 5, null , null , null FROM dual ) SELECT * FROM ( SELECT id , mon , CHR(lv+64) code , DECODE(lv, 1, a, 2, b, 3, c, 4, d, 5, e, 6, f) val FROM t , ( SELECT LEVEL lv FROM dual CONNECT BY LEVEL <= 6) ) WHERE val IS NOT NULL ORDER BY id, mon, code ; |