tags:

views:

273

answers:

3

Here's the sample SQL:

SELECT xml_data.field
FROM
  (SELECT sys.XMLType(source_table.data).extract('//source_node/text()') AS field
  FROM source_table
  )xml_data
GROUP BY to_clob(xml_data.field)

The error only appears when I use GROUP BY to do a count. When it is removed I get the error

ORA-22806: not an object or REF
22806. 00000 - "not an object or REF"
*Cause: An attempt was made to extract an attribute from an
        item that is neither an object nor a REF.
*Action: Use an object type or REF type item and retry the operation.
Vendor code 22804Error at Line:1

Is GROUP BY somehow mutating the type of the XML field returned in the sub query? Or (more than likely) am I just missing something?

It is worth noting that the source_table.data column is a CLOB.

A: 
SELECT  field
FROM    (
        SELECT  SYS.XMLType.getstringval(SYS.XMLType('<source_node>test</source_node>').extract('//source_node/text()')) AS field
        FROM    dual
        ) xml_data
GROUP BY
        field
Quassnoi
I'm afraid this gave me the same error.
Pascal Dennerly
This worked on my 10g XE. Which version do you use?
Quassnoi
9.2.0.8i connecting using SQLDeveloper 1.5.4
Pascal Dennerly
Oh. Can't have a 9i handy to check, sorry.
Quassnoi
A: 

the following worked for me in 9.2

SELECT  SYS.XMLType.getstringval(SYS.XMLType('<source_node>test</source_node>').extract('//source_node/text()')) AS field
FROM    dual      
group by SYS.XMLType.getstringval(SYS.XMLType('<source_node>test</source_node>').extract('//source_node/text()'))
 ;
moleboy
I'm afraid this doesn't work either. ORA-22806 again.
Pascal Dennerly
I'm running through TOAD against a 9.2.0.8.0 database.Can you confirm your database version?I can't imagine this will make a difference, but also try through SQLPlus
moleboy
+1  A: 

I see the same error:

SQL> select * from v$version;

BANNER
-------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
PL/SQL Release 9.2.0.1.0 - Production
CORE    9.2.0.1.0       Production
TNS for 32-bit Windows: Version 9.2.0.1.0 - Production
NLSRTL Version 9.2.0.1.0 - Production

I did some rearranging of the function calls in the select statement, this causes the error to disappear.

create table source_table (data clob);
insert into source_table values ('<source_node>test</source_node>');
commit;

select xmltype.getstringval((field).extract('//source_node/text()'))
from
(
  select  xmltype(data) field
  from    source_table
)
group by xmltype.getstringval((field).extract('//source_node/text()'))
/

You have to use ((field).extract... instead of (field.extract...

tuinstoel