前面已經有出色的APC說,這個版本是真的老了,缺乏各種功能做字符串聚集。我曾在以前的千禧年7版本雖然工作了,我想下一個序列應該在Oracle7的工作。我可能是錯的,但顯然我無法檢查它。
SQL> create table t (fo,line,floor,color,sum)
2 as
3 select 'S4714EH02', 'EH', '11F', 'AK', 9 from dual union all
4 select 'S4714EH02', 'EH', '11F', 'AK', 18 from dual union all
5 select 'S4714EH02', 'EH', '11F', 'FE', 9 from dual union all
6 select 'S4714EH02', 'EH', '11F', 'FE', 18 from dual union all
7 select 'S4714EH02', 'EH', '12F', 'AK', 9 from dual union all
8 select 'S4714EH02', 'EH', '12F', 'AK', 18 from dual union all
9 select 'S4714EH02', 'EH', '12F', 'FE', 9 from dual union all
10 select 'S4714EH02', 'EH', '12F', 'FE', 18 from dual
11/
Table created.
SQL> create function f
2 (p_fo in t.fo%type
3 , p_line in t.line%type
4 , p_floor in t.floor%type
5 , p_color in t.color%type
6 ) return varchar2
7 is
8 cursor c
9 is
10 select t.sum
11 from t
12 where t.fo = p_fo
13 and t.line = p_line
14 and t.floor = p_floor
15 and t.color = p_color
16 order by t.sum
17 ;
18 l_concatenated_sum varchar2(2000);
19 begin
20 for r in c
21 loop
22 l_concatenated_sum := l_concatenated_sum || ',' || to_char(r.sum);
23 end loop;
24 return substr(l_concatenated_sum,2);
25 end f;
26/
Function created.
SQL> select fo
2 , line
3 , floor
4 , color
5 , f(fo,line,floor,color) sum
6 from t
7 group by fo
8 , line
9 , floor
10 , color
11/
FO LI FLO CO SUM
--------- -- --- -- --------------------
S4714EH02 EH 11F AK 9,18
S4714EH02 EH 11F FE 9,18
S4714EH02 EH 12F AK 9,18
S4714EH02 EH 12F FE 9,18
4 rows selected.
問候,
羅布。
Oracle 7?真的沒辦法升級? – Thilo 2011-03-17 06:13:27