Select xml element value in Oracle

前端 未结 4 1256
长发绾君心
长发绾君心 2020-12-21 15:37

I am trying to extract a value from an xml element, located in an XMLTYPE column in an Oracle Table. The xml element which I am trying to extract have a parent for which a n

相关标签:
4条回答
  • 2020-12-21 16:18
    SELECT XMLAGG(XMLELEMENT(E,ename||',')).EXTRACT('//text()') "Result"
    FROM   emp
    
    0 讨论(0)
  • 2020-12-21 16:26
    select a.*
    from   XMLTABLE(
             XMLNAMESPACES('urn:www.someSite.com/myModel' AS "ns"),
             '/*'
             PASSING my.myColumn           
             COLUMNS
               val  VARCHAR2(2000)   PATH '/a/ns:b/ns:c'
           ) a, myTable my;
    
    0 讨论(0)
  • 2020-12-21 16:34

    Since the a element does not have the namespace, you can first extract its child elements without using namespaces in the function, and then extract the value from the b with the namespace:
    Try:

    select extract(extract(myColumn, 'a/*'),
                   'b/c/text()',
                   'xmlns=urn:www.someSite.com/myModel') 
      from myTable
    
    0 讨论(0)
  • 2020-12-21 16:34

    When the default namespace changes, one way to specify namespaces is to write the wildcard character ('*') and the local-name() and namespace-uri() XPath functions.

    select extract(myColumn, '/a/*[local-name()='b' and namespace-uri()='urn:www.someSite.com/myModel']/*[local-name()='c' and namespace-uri()='urn:www.someSite.com/myModel']') from myTable

    0 讨论(0)
提交回复
热议问题