Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle SQL - Extracting clob value from XML with repeating nodes

Tags:

sql

xml

oracle

I am attempting to run SQL on a table (called test_xml with a column xml_data [data type xmltype]). The column contains xml with repeating nodes (test_3). The following statement runs successfully when the node contains data of a non clob size:

SELECT 
   extractvalue (Value (wl), '*/test_3')
      FROM test_xml
         , TABLE (xmlsequence (extract (xml_data, '*/record'))) wl

but fails when test_3 node contains a lot of data:

ORA-01706: user function result value was too large

I amended my query:

SELECT 
   extractvalue(Value (wl), '*/test_3').getClobVal()
      FROM test_xml
         , TABLE (xmlsequence (extract (xml_data, '*/record'))) wl

but this fails with:

ORA-22806: not an object or REF

like image 588
Greg Cox Avatar asked Dec 09 '12 00:12

Greg Cox


People also ask

How do I select a specific XML node in SQL Server?

You should use the query() Method if you want to get a part of your XML. If you want the value from a specific node you should use value() Method. Update: If you want to shred your XML to multiple rows you use nodes() Method.

Which of the below XML data type method or methods would you use to retrieve scalar values from an XML instance?

Using the value() and exist() methods to retrieve values from an xml type column. The following example shows using both the value() method and the exist() method of the xml data type. The value() method is used to retrieve ProductModelID attribute values from the XML.


1 Answers

This was resolved via a response received on Oracle Forums:

See Forum Post

From Oracle release 11.2.0.2:

SELECT x.*
FROM test_xml t
   , XMLTable(
       '/*/record'
       passing t.xml_data
       columns
         test_3  clob path 'test_3'
     ) x
;

My database version is 10.2.0.4 hence the following 'trick' is required:

SELECT dbms_xmlgen.convert(x.test_3.getClobVal(), 1) as test_3
FROM test_xml t
   , XMLTable(
       '/*/record'
       passing t.xml_data
       columns
         test_3  xmltype path 'test_3/text()'
     ) x
;

Thanks go to odie_63 for this

like image 150
Greg Cox Avatar answered Oct 06 '22 00:10

Greg Cox