Skip to Main Content
  • Questions
  • Group By error for Subquery using XMLTABLE

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Colin.

Asked: September 24, 2025 - 1:38 pm UTC

Last updated: September 26, 2025 - 2:37 pm UTC

Version: 19C

Viewed 100+ times

You Asked

This is my example data:

CREATE TABLE xml_test (
    xml_col XMLTYPE NOT NULL);
/* */
INSERT INTO xml_test VALUES (XMLTYPE('<ns1:SomeRootNode xmlns="http://www.exampleurl.com" xmlns:ns1="http://www.someotherurl.com">
  <ns1:SomeParentNode>
    <ns1:SomeRepeatingNode>
      <ns1:SomeDataNode>12345</ns1:SomeDataNode>
    </ns1:SomeRepeatingNode>
    <ns1:SomeRepeatingNode>
      <ns1:SomeDataNode>23456</ns1:SomeDataNode>
    </ns1:SomeRepeatingNode>
    <ns1:SomeRepeatingNode>
      <ns1:SomeDataNode>12345</ns1:SomeDataNode>
    </ns1:SomeRepeatingNode>
    <ns1:SomeRepeatingNode>
      <ns1:SomeDataNode>23456</ns1:SomeDataNode>
    </ns1:SomeRepeatingNode>
    <ns1:SomeRepeatingNode>
      <ns1:SomeDataNode>12345</ns1:SomeDataNode>
    </ns1:SomeRepeatingNode>
  </ns1:SomeParentNode>
</ns1:SomeRootNode>'));
COMMIT;


This works perfectly fine:

SELECT b.*
FROM   xml_test a,
       XMLTABLE('//*:SomeDataNode'
           PASSING(a.xml_col)
           COLUMNS 
               data_value NUMBER(6) PATH '.') b


|DATA_VALUE|
|----------|
|12345 |
|23456 |
|12345 |
|23456 |
|12345 |

But this throws an ORA-00979 error:

SELECT data_value,
       count(*)
FROM (
 SELECT b.*
 FROM   xml_test a,
        XMLTABLE('//*:SomeDataNode'
            PASSING(a.xml_col)
            COLUMNS 
                data_value NUMBER(6) PATH '.') b)
GROUP BY data_value


I can't see anything obviously wrong here (but I have been looking at it for a while so may be missing something obvious). Any ideas why I'm getting an error?

and Chris said...

It looks correct to me too and it works in 23.9:

select banner_full from v$version;

BANNER_FULL
-----------------------------------------------------------------------------------------------------------
Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for FreeVersion 23.9.0.25.07

SELECT data_value,
       count(*)
FROM (
 SELECT b.*
 FROM   xml_test a,
        XMLTABLE('//*:SomeDataNode'
            PASSING(a.xml_col)
            COLUMNS 
                data_value NUMBER(6) PATH '.') b)
GROUP BY data_value;

DATA_VALUE   COUNT(*)
---------- ----------
     12345          3
     23456          2


So this looks like a bug; reach out to support to see about getting a backport.

Rating

  (1 rating)

Comments

Bug was added in version 19

mathguy, September 26, 2025 - 1:46 pm UTC

For what it's worth, the code works as expected, not only in version 23, but also on 12.2.0.1. The bug was added in version 19 and then fixed by version 23; I don't have a copy of v. 21 to test.
Chris Saxon
September 26, 2025 - 2:37 pm UTC

Thanks for investigating.