sql - 从 xmltype/soap oracle 中提取值
问题描述
我需要从字段中获取“ineedthis”值
REQUEST_INFO:
...
<s:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<X-dynaTrace xmlns="http://ns.dynatrace.com/wcf" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">FW3;-1003312095;1;-56375709;115092;0;975784079;78</X-dynaTrace>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<storeContract xmlns="xxx/integration">
<storeRequest>
<contract>
<contractSeries>ineedthis</contractSeries>
select extractvalue(XMLType(sap.REQUEST_INFO),'s/s/storeContract/storeRequest/contract/contractSeries')
from sap
无法获得价值
解决方案
您正在尝试提取路径
s/s/storeContract/storeRequest/contract/contractSeries
但是您的 SOAP 响应没有任何名为的节点s
;它在命名空间 s
中有名为 Envelope、Header 和 Body 的节点。所以你可能想要路径:
/s:Envelope/s:Body/storeContract/storeRequest/contract/contractSeries
它本身会LPX-00601: Invalid token
出错,因为它不知道是什么s:
。您可以为命名空间提供第三个参数:
select extractvalue(XMLType(sap.request_info),
'/s:Envelope/s:Body/storeContract/storeRequest/contract/contractSeries',
'xmlns="xxx/integration" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"'
) as contractseries
from sap;
或者懒惰的方法是使用通配符命名空间并仅识别您想要的最终节点:
select extractvalue(XMLType(sap.request_info),'//*:contractSeries') as contractseries
from sap;
但是extractvaue
已弃用,因此最好使用 XMLQuery - 仍然很懒惰:
select XMLQuery('//*:contractSeries/text()'
passing XMLType(sap.request_info)
returning content) as contractseries
from sap;
或使用显式命名空间:
select XMLQuery('
declare default element namespace "xxx/integration";
declare namespace s="http://schemas.xmlsoap.org/soap/envelope/";
/s:Envelope/s:Body/storeContract/storeRequest/contract/contractSeries/text()'
passing XMLType(sap.request_info)
returning content) as contractseries
from sap;
CONTRACTSERIES
------------------------------
ineedthis
推荐阅读
- sql - 嵌套 sql 聚合函数的语法
- node.js - 在 MacOS 中使用 Homebrew 安装节点时卡住了:fork.rb:49:in `write': Broken pipe (Errno::EPIPE)
- java - 如何在 Heroku 中运行 Spring Boot WAR 应用程序?
- matplotlib-basemap - 底图加 3d 图
- python - Python:数组的numpy数组的外积的所有排列的总和
- java - Ubuntu 上的 Javac
- pdf - 重命名 PDF 嵌入字体
- kotlin - 将 Java 转换为 Kotlin(以函数作为参数)
- php - laravel 控制器中未收到复选框值
- python - 按钮“开始”以其他五个按钮结束,每个按钮一个。tkinter