2012-02-07 98 views
0

我有一個表格和值,如下例所示,當我選擇時,我需要結果以逗號分隔的單行形式提供。以單行逗號分隔的格式選擇查詢結果

Table1.new_field 值1 值2 值3

我需要的結果如下的選擇查詢。

值1,值2,值3 ...

我檢查喜歡wm_concat但沒有運氣的功能。我正在使用Oracle 10g。請建議如何實現這一點。

TIA。

回答

0

我想你想在MySQL中使用GROUP_CONCAT函數。但不幸的是,在oracle中沒有內建函數。

你可能想看看這篇文章:GROUP_CONCAT in Oracle 10gthis one

with data 
as 
(
    select job, 
    ename, 
    row_number() over (partition by job order by ename) rn, 
    count(*) over (partition by job) cnt 
    from emp 
) 
select job, ltrim(sys_connect_by_path(ename,','),',') scbp 
    from data 
    where rn = cnt 
    start with rn = 1 
    connect by prior job = job and prior rn = rn-1 
    order by job 
/

JOB  SCBP 
--------- ---------------------------------------- 
ANALYST FORD,SCOTT 
CLERK  ADAMS,JAMES,MILLER,SMITH 
MANAGER BLAKE,CLARK,JONES 
PRESIDENT KING 
SALESMAN ALLEN,MARTIN,TURNER,WARD