You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Oracle中从CLOB类型XML提取NAME节点值

Extract NAME Node Value from XML in CLOB Column

Got it, let's work through this. You need to pull the text value from the <NAME> node inside the XML stored in your test_clob table's data_value CLOB column. The critical detail here is handling the default XML namespace in your XML content—skip this, and your queries won't find the nodes you're targeting.

This is the go-to method for Oracle 12c and later, as it’s flexible and avoids deprecated functions:

SELECT x.name_value
FROM test_clob,
     XMLTable(
       XMLNAMESPACES(default 'urn:dataworld-com:schemas:custom_navigator_node'),
       '/CustomNavigatorNode/NAME'
       PASSING XMLTYPE(data_value)
       COLUMNS name_value VARCHAR2(255) PATH '.'
     ) x;

Quick Breakdown:

  • XMLTYPE(data_value): Converts the raw CLOB content into an XMLType object that Oracle can parse.
  • XMLNAMESPACES(...): Declares the default namespace from your XML (xmlns="urn:dataworld-com:schemas:custom_navigator_node"), so the parser recognizes the node structure correctly.
  • /CustomNavigatorNode/NAME: The XPath that targets the <NAME> node under the root <CustomNavigatorNode>.
  • COLUMNS name_value ... PATH '.': Defines a column to hold the extracted text, where . refers to the text content of the current <NAME> node.

Solution 2: Using EXTRACTVALUE (Legacy Compatibility)

If you’re working with an older Oracle version (pre-12c), you can use EXTRACTVALUE (note: this function is deprecated in newer releases):

SELECT EXTRACTVALUE(
         XMLTYPE(data_value),
         '/CustomNavigatorNode/NAME',
         'xmlns="urn:dataworld-com:schemas:custom_navigator_node"'
       ) AS name_value
FROM test_clob;

Quick Breakdown:

  • The third parameter explicitly passes the namespace declaration to the function, ensuring it matches the XML’s structure so the node is found.

Expected Output

Both queries will return exactly what you’re looking for:

NAME_VALUE
-------------------
Data report Value

Quick Notes

  • Ensure the XML in your CLOB is well-formed (no syntax errors), otherwise the XML conversion step will fail.
  • If your table has multiple rows with XML content, these queries will return the <NAME> value for each row.

内容的提问来源于stack exchange,提问作者Mohd Shoeb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:16:43