我正在用plsql调用Soap Service,并且得到xml格式的响应 我想解析xml,并想在Oracle Table中保存一个值。 在xml输出下面:
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<ActivityId xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics" CorrelationId="3c08103b-65da-4f34-95e7-ec2c90ba5b74">00000000-0000-0000-0000-000000000000</ActivityId>
<o:Security xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="1">
<u:Timestamp u:Id="_0">
<u:Created>2019-04-16T20:21:06.467Z</u:Created>
<u:Expires>2019-04-16T20:26:06.467Z</u:Expires>
</u:Timestamp>
</o:Security>
</s:Header>
<s:Body>
<SaveSalesResponse xmlns="https://unifree.com.tr/services/custom">
<SaveSalesResult xmlns:a="http://schemas.datacontract.org/2004/07/CustomServiceLibrary.DataContract" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:Result>true</a:Result>
<a:Provision>
<a:ProvisionNo>245982</a:ProvisionNo>
</a:Provision>
</SaveSalesResult>
</SaveSalesResponse>
</s:Body>
</s:Envelope>
我要将<a:ProvisionNo>245982</a:ProvisionNo>
这个号码保存在表格中
请提出一种在表格中存储价值的简单方法
答案 0 :(得分:0)
With the premise that the example document you provided is representative of the layout of document being used (that there is only one <s:Body>
, with only one <SaveSalesResponse>
, and so forth to a single <a:PorivisionNo>
per document, then EXTRACTVALUE
is all that should be required.
If your data set includes more complex structures housing multiple <a:ProvisionNo>
per document, I would recommend extracting the values with XMLQUERY
/XMLTABLE
instead.
An example of loading a table with the <a:ProvisionNo>
via EXTRACTVALUE
is below.
CREATE TABLE PROVISION_NO(THE_PROVISION_NO INTEGER);
Table created.
Then run the load:
INSERT INTO PROVISION_NO(THE_PROVISION_NO)
SELECT EXTRACTVALUE( XMLTYPE('<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<ActivityId xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics" CorrelationId="3c08103b-65da-4f34-95e7-ec2c90ba5b74">00000000-0000-0000-0000-000000000000</ActivityId>
<o:Security xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="1">
<u:Timestamp u:Id="_0">
<u:Created>2019-04-16T20:21:06.467Z</u:Created>
<u:Expires>2019-04-16T20:26:06.467Z</u:Expires>
</u:Timestamp>
</o:Security>
</s:Header>
<s:Body>
<SaveSalesResponse xmlns="https://unifree.com.tr/services/custom">
<SaveSalesResult xmlns:a="http://schemas.datacontract.org/2004/07/CustomServiceLibrary.DataContract" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:Result>true</a:Result>
<a:Provision>
<a:ProvisionNo>245982</a:ProvisionNo>
</a:Provision>
</SaveSalesResult>
</SaveSalesResponse>
</s:Body>
</s:Envelope>'),
'/s:Envelope/s:Body/*:SaveSalesResponse/*:SaveSalesResult/a:Provision/a:ProvisionNo',
'xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://schemas.datacontract.org/2004/07/CustomServiceLibrary.DataContract" ')
FROM DUAL;
1 row created.
And the result:
SELECT THE_PROVISION_NO FROM PROVISION_NO;
THE_PROVISION_NO
___________________
245982
1 row selected.