温馨提示×

Oracle extractValue函数怎样使用

小樊
147
2024-07-19 18:37:37
栏目: 云计算

Oracle的extractValue函数用于从XML文档中提取指定路径的值。其基本语法如下:

extractValue(xmltype_instance, xpath_expression)

其中,xmltype_instance是一个XMLType类型的实例,表示要从中提取值的XML文档;xpath_expression是一个XPath表达式,用于指定要提取的值的路径。

例如,假设有以下XML文档:

<bookstore>
  <book category="children">
    <title lang="en">Harry Potter</title>
    <author>J.K. Rowling</author>
  </book>
</bookstore>

要提取书名(title)的值,可以使用以下SQL语句:

SELECT EXTRACTVALUE(xmltype('<bookstore><book category="children"><title lang="en">Harry Potter</title><author>J.K. Rowling</author></book></bookstore>'), '/bookstore/book/title') AS title
FROM dual;

运行结果将返回:

title
----------
Harry Potter

需要注意的是,Oracle 12c版本开始已经弃用了extractValue函数,推荐使用XMLTable或XMLQuery函数来处理XML文档。

0