ORA-00979 Not a GROUP BY Expression with complex EXTRACTVALUE

心不动则不痛 提交于 2019-12-12 17:26:50

问题


I'm trying to execute a rather simple Oracle query against a table with a XMLTYPE column:

Select POB_CODPOL, CODSIS From (
    Select T1.POB_CODPOL, EXTRACTVALUE(T1.POB_XMLPOL, '/Polbas/polfun[nomfun="filterBySystem"]/extpar[codele="codsis"]/valele/text()') CODSIS 
    From TDTX_POLITICA_CLOB T1
    Where T1.POB_CODEMP = '001840' 
)     
Group By POB_CODPOL, CODSIS

This throws a ORA-00979 Not a GROUP BY Expression, which I don't really understand. Even worse: when I execute the exact same query, but with a simplified XPATH query does work:

Select POB_CODPOL, CODSIS From (
    Select T1.POB_CODPOL, EXTRACTVALUE(T1.POB_XMLPOL, 'Polbas/codpol/text()') CODSIS 
    From TDTX_POLITICA_CLOB T1
    Where T1.POB_CODEMP = '001840' 
)     
Group By POB_CODPOL, CODSIS

It looks like Oracle doesn't like conditions like [nomfun="filterBySystem"] when using a GROUP BY (without the grouping clause, everything works fine).

Any idea on why this can be happening?

Edit: the result of the inner query is rather simple:


回答1:


EXTRACTVALUE is deprecated.

Oracle recommends to use XMLQUERY, XMLTABLE for it.

This one should work:

WITH t as
    (SELECT T1.POB_CODPOL, x.CODSIS 
     FROM TDTX_POLITICA_CLOB T1 
          NATURAL JOIN XMLTABLE('/Polbas/polfun[nomfun="filterBySystem"]/extpar[codele="codsis"]/valele‌​' 
             PASSING POB_XMLPOL COLUMNS 
             CODSIS VARCHAR2(50) PATH '/') x
     Where T1.POB_CODEMP = '001840')
SELECT POB_CODPOL, CODSIS 
FROM t
GROUP BY POB_CODPOL, CODSIS;


来源:https://stackoverflow.com/questions/32824304/ora-00979-not-a-group-by-expression-with-complex-extractvalue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!