我有一个表和值如下例所示,当我选择时,我需要将结果以逗号分隔的单行显示。
Table1.new_field 值1 值2 值3
我需要选择查询的结果如下。
value1,value2,value3 ...
我检查过像wm_concat这样的功能,但没有运气。我正在使用oracle 10g。请建议如何实现这一目标。
TIA。
答案 0 :(得分:0)
我想你想在MySQL中使用GROUP_CONCAT
函数。但不幸的是,在oracle中没有内置函数。
您可以查看以下文章:GROUP_CONCAT in Oracle 10g和this 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