0

我的LISTAGG功能有问题。我不断收到错误ORA-00937: not a single group function。我已经用谷歌搜索了这个错误,但仍然不太清楚出了什么问题。

场景:我有一个细分表。一个段可以有多个人分配给他们(一对多)。我需要我的输出/报告在一列中显示段号,在另一列中显示用户列表。

查询

    select fcs.nld_flood_control_segment_id
         , fcs.fc_segment_name
         , fcs.fc_segment_abbrev_name
         , LISTAGG(ps.first_name|| ' ' ||ps.last_name, ', ') within group (ORDER BY fcs.nld_flood_control_segment_id, ps.last_name) "ListOfReps"
      from nld_flood_control_segments   fcs
         , nld_fc_segment_person_xref   xr
         , persons                      ps
     where fcs.nld_flood_control_segment_id = :P1_id
       and :P1_id                           = xr.nld_flood_control_segment_id 
       and xr.person_id                     = ps.person_id
  order by nld_flood_control_segment_id asc
         ;

任何帮助将不胜感激。提前致谢。

4

1 回答 1

2

LISTAGG 函数具有以下语法结构:

LISTAGG( [,]) WITHIN GROUP (ORDER BY ) [OVER (PARTITION BY )]

LISTAGG 是一个聚合函数,可以选择用作分析(即可选的 OVER() 子句)。以下元素是强制性的:

the column or expression to be aggregated;
the WITHIN GROUP keywords;
the ORDER BY clause within the grouping.

例子:

LISTAGG(ename, ',') WITHIN GROUP (ORDER BY ename) AS employees

尝试以下操作,看看它是否能满足您的需求。

LISTAGG(ps.first_name|| ' ' ||ps.last_name, ',') within group (ORDER BY ps.first_name|| ' ' ||ps.last_name) "ListOfReps"
于 2013-08-02T15:10:03.230 回答