我想写一个 sql 查询来获取 soap xml 中两个标签之间的数据,这些标签存在于 oracle table 的 clob 列中
i want write a sql query to fetch data between two tags in soap xml which present in the clob column of a oracle table
xml which is present ina clob column of xml_message table :
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:oag="http://gateway.consumerhub.commercial.volvocars.net/oagis" xmlns:oag1="http://www.openapplications.org/oagis" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<oag:UpdateConsumerAndOpportunityData_v1 xmlns:ns3="http://www.ford.com/oagis">
<oag1:ApplicationArea>
<oag1:Sender>
<oag1:LogicalId>Volvo</oag1:LogicalId>
<oag1:Component>Vista</oag1:Component>
<oag1:Task>SyncConsumer</oag1:Task>
<oag1:AuthorizationId>AUTH-SK034</oag1:AuthorizationId>
</oag1:Sender>
<oag1:CreationDateTime>2016-01-27T15:07:47Z</oag1:CreationDateTime>
<oag1:BODId>sk-connect-034</oag1:BODId>
</oag1:ApplicationArea>
<oag:DataArea>
<oag1:Sync confirm="Always">
<oag1:SyncCriteria expressionLanguage="XPath">
<oag1:SyncExpression action="change"/>
</oag1:SyncCriteria>
</oag1:Sync>
<oag:Consumer>
<oag:Header>
<oag:Source>AU</oag:Source>
</oag:Header>
<oag:ConsumerDetails Category="Person">
<oag:ConsumerId/>
<oag:Language>EN</oag:Language>
<oag:PersonDetails>
<oag:FirstName>firstname_email_034</oag:FirstName>
<oag:Surname>sname_email_034</oag:Surname>
</oag:PersonDetails>
<oag:EmailAddress Active="true">ticc888@yahoo.com</oag:EmailAddress>
<oag:EmailAddress Active="true" Usage="Business">ahng2@hotmail.com</oag:EmailAddress>
<oag:EmailAddress Active="true" Usage="Invoice">jsmith@gmail.com</oag:EmailAddress>
</oag:ConsumerDetails>
</oag:Consumer>
</oag:DataArea>
</oag:UpdateConsumerAndOpportunityData_v1>
</soapenv:Body>
</soapenv:Envelope>
现在我想要从这个 xml 获取所有电子邮件地址并插入到另一个 table。
此 xml 包含 3 个电子邮件地址,我希望获取直到 n 个电子邮件地址,一个 xml 文件将包含
如链接答案所示,您可以使用 XMLTable 提取多个值;但您至少需要定义您使用的名称空间,并正确构造 XPath。因此,要仅获取电子邮件地址,您可以执行以下操作:
select x.emailaddress
from xml_message m
cross apply xmltable (
xmlnamespaces (
'http://schemas.xmlsoap.org/soap/envelope/' as "soapenv",
'http://gateway.consumerhub.commercial.volvocars.net/oagis' as "oag",
'http://www.openapplications.org/oagis' as "oag1",
'http://www.ford.com/oagis' as "ns3"
),
'soapenv:Envelope/soapenv:Body/oag:UpdateConsumerAndOpportunityData_v1/oag:DataArea/oag:Consumer/oag:ConsumerDetails/oag:EmailAddress'
passing xmltype(m.xml_clob)
columns
EmailAddress varchar2(64) path '.'
) x;
EMAILADDRESS
ticc888@yahoo.com
ahng2@hotmail.com
jsmith@gmail.com
XPath 不引用 oag1 或 ns3,但包含它们也无妨,您可能需要它们从同一个 XML 文档中提取其他信息。
这还可以让您一次提取多个值;或者基于属性进行过滤 - 例如,您可能只想包含属性 Active 设置为 true 的电子邮件地址,您可以通过将该条件添加到 XPath 来实现:
'soapenv:Envelope/soapenv:Body/oag:UpdateConsumerAndOpportunityData_v1/oag:DataArea/oag:Consumer/oag:ConsumerDetails/oag:EmailAddress[@Active="true"]'
您可以阅读更多关于操纵 XML in the documentation.
xml which is present ina clob column of xml_message table :
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:oag="http://gateway.consumerhub.commercial.volvocars.net/oagis" xmlns:oag1="http://www.openapplications.org/oagis" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<oag:UpdateConsumerAndOpportunityData_v1 xmlns:ns3="http://www.ford.com/oagis">
<oag1:ApplicationArea>
<oag1:Sender>
<oag1:LogicalId>Volvo</oag1:LogicalId>
<oag1:Component>Vista</oag1:Component>
<oag1:Task>SyncConsumer</oag1:Task>
<oag1:AuthorizationId>AUTH-SK034</oag1:AuthorizationId>
</oag1:Sender>
<oag1:CreationDateTime>2016-01-27T15:07:47Z</oag1:CreationDateTime>
<oag1:BODId>sk-connect-034</oag1:BODId>
</oag1:ApplicationArea>
<oag:DataArea>
<oag1:Sync confirm="Always">
<oag1:SyncCriteria expressionLanguage="XPath">
<oag1:SyncExpression action="change"/>
</oag1:SyncCriteria>
</oag1:Sync>
<oag:Consumer>
<oag:Header>
<oag:Source>AU</oag:Source>
</oag:Header>
<oag:ConsumerDetails Category="Person">
<oag:ConsumerId/>
<oag:Language>EN</oag:Language>
<oag:PersonDetails>
<oag:FirstName>firstname_email_034</oag:FirstName>
<oag:Surname>sname_email_034</oag:Surname>
</oag:PersonDetails>
<oag:EmailAddress Active="true">ticc888@yahoo.com</oag:EmailAddress>
<oag:EmailAddress Active="true" Usage="Business">ahng2@hotmail.com</oag:EmailAddress>
<oag:EmailAddress Active="true" Usage="Invoice">jsmith@gmail.com</oag:EmailAddress>
</oag:ConsumerDetails>
</oag:Consumer>
</oag:DataArea>
</oag:UpdateConsumerAndOpportunityData_v1>
</soapenv:Body>
</soapenv:Envelope>
现在我想要从这个 xml 获取所有电子邮件地址并插入到另一个 table。 此 xml 包含 3 个电子邮件地址,我希望获取直到 n 个电子邮件地址,一个 xml 文件将包含
如链接答案所示,您可以使用 XMLTable 提取多个值;但您至少需要定义您使用的名称空间,并正确构造 XPath。因此,要仅获取电子邮件地址,您可以执行以下操作:
select x.emailaddress
from xml_message m
cross apply xmltable (
xmlnamespaces (
'http://schemas.xmlsoap.org/soap/envelope/' as "soapenv",
'http://gateway.consumerhub.commercial.volvocars.net/oagis' as "oag",
'http://www.openapplications.org/oagis' as "oag1",
'http://www.ford.com/oagis' as "ns3"
),
'soapenv:Envelope/soapenv:Body/oag:UpdateConsumerAndOpportunityData_v1/oag:DataArea/oag:Consumer/oag:ConsumerDetails/oag:EmailAddress'
passing xmltype(m.xml_clob)
columns
EmailAddress varchar2(64) path '.'
) x;
EMAILADDRESS |
---|
ticc888@yahoo.com |
ahng2@hotmail.com |
jsmith@gmail.com |
XPath 不引用 oag1 或 ns3,但包含它们也无妨,您可能需要它们从同一个 XML 文档中提取其他信息。
这还可以让您一次提取多个值;或者基于属性进行过滤 - 例如,您可能只想包含属性 Active 设置为 true 的电子邮件地址,您可以通过将该条件添加到 XPath 来实现:
'soapenv:Envelope/soapenv:Body/oag:UpdateConsumerAndOpportunityData_v1/oag:DataArea/oag:Consumer/oag:ConsumerDetails/oag:EmailAddress[@Active="true"]'
您可以阅读更多关于操纵 XML in the documentation.