ORA-00937: 不是单个组函数 (XMLAGG)

ORA-00937: not a single group function (XMLAGG)

我在单行中使用了 XMLAGG 聚合函数,但我一直收到错误代码 ORA-00937。为什么?

报告的结构是:

<Forms>
    <Year>2015</Year>
    <Month>September</Month>
    <Date>2015-09-22</Date>
    <Form>A1</Form>
    <Form>B4</Form>
    …
</Forms>

我的select声明是:

SELECT XMLSERIALIZE(
  DOCUMENT XMLROOT(
     XMLELEMENT("Forms",XMLATTRIBUTES('http://www.w3.org/2001/XMLSchema-    instance' AS "xmlns:xsi"),
         XMLELEMENT("Year", b.Year),
         XMLELEMENT("Month", b.Month),
         XMLELEMENT("Date", b.r_modify_date),
            XMLAGG(XMLELEMENT"Form",b.docnum))               
       ), 
      )  
    ) 
 FROM xml_bill  b
 where trunc(b.R_MODIFY_DATE) =trunc(sysdate);

所以我在WHERE子句中加入了GROUP BY,在SELECT语句中修改了XMLELEMENT(“Date”, trunc(b.r_modify_date)

这是新查询:

SELECT XMLSERIALIZE(
        DOCUMENT XMLROOT(
            XMLELEMENT("Forms",XMLATTRIBUTES('http://www.w3.org/2001/XMLSchema-instance' AS "xmlns:xsi"),
                XMLELEMENT("Year", b.Year),
                XMLELEMENT("Month", b.Month),
                XMLELEMENT("Date", trunc(b.R_MODIFY_DATE)),
                    XMLAGG(
                            XMLELEMENT("Form", b.DOCNUM)
                           )
                ),
            )  
    )
 FROM xml_bill  b
where
trunc(b.R_MODIFY_DATE) =trunc(sysdate)
GROUP BY b.Year, b.Month,trunc(b.R_MODIFY_DATE);