【问题标题】:Oracle 12c, Store SOAP response into variable or insert to tableOracle 12c,将 SOAP 响应存储到变量中或插入到表中
【发布时间】:2021-06-01 15:44:25
【问题描述】:

我是 PL/SQL 新手并使用 SOAP ws。我设法获得了 SOAP 响应 XML,并且我正在使用 XMLTable 从中提取数据,但是我得到了奇怪的数据格式。这是我遇到问题的选择:

select item
            from XMLTable(
  XMLNamespaces (
    default 'urn:DHCPProv',
    'http://schemas.xmlsoap.org/soap/envelope/' as "soap",
    'http://schemas.xmlsoap.org/soap/encoding/' as "soapenc"
  ),
  '/soap:Envelope/soap:Body/getDhcpForPortResponse/soapenc:Array/item/item'
  passing XMLType('<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
            <getDhcpForPortResponse
                xmlns="urn:DHCPProv">
                <soapenc:Array
                    soapenc:arrayType="soapenc:Array[2]"
                    xsi:type="soapenc:Array">
                    <item
                        soapenc:arrayType="xsd:string[5]"
                        xsi:type="soapenc:Array">
                        <item
                            xsi:type="xsd:string">
                            qbtp8482tv
                            </item>
                        <item
                            xsi:type="xsd:string">
                            111.11.111.111
                            </item>
                        <item
                            xsi:type="xsd:string">
                            bc644ba2501c
                            </item>
                        <item
                            xsi:type="xsd:string">
                            MF5601T_AMD-NDF
                            </item>
                        <item
                            xsi:type="xsd:string"/>
                        </item>
                    <item
                        soapenc:arrayType="xsd:string[5]"
                        xsi:type="soapenc:Array">
                        <item
                            xsi:type="xsd:string">
                            qbtp8482tv
                            </item>
                        <item
                            xsi:type="xsd:string">
                            222.22.222.222
                            </item>
                        <item
                            xsi:type="xsd:string">
                            704fb8f3e4e1
                            </item>
                        <item
                            xsi:type="xsd:string">
                            MF5601T_AMD-NDF
                            </item>
                        <item
                            xsi:type="xsd:string"/>
                        </item>
                    </soapenc:Array>
                </getDhcpForPortResponse>
 </soap:Body>
 </soap:Envelope>')
  columns item varchar2(4000) path '.'
);

我想知道是否有办法将此格式存储到变量中或以某种方式将其插入表中? 谢谢!

【问题讨论】:

  • 我假设“奇怪的格式”是指在实际值之前/之后有空行和空格。我认为这听起来很熟悉......我在上一个问题的my answer 中提到了这一点以及如何解决它。将值插入表中并没有什么特别之处。

标签: xml soap oracle12c


【解决方案1】:

您的 XML 在节点值中有换行符和空格。如果你想删除那些你可以做的:

select rtrim(ltrim(item, chr(32)||chr(10)), chr(10)||chr(32)) as item

给出 10 行:

ITEM
--------------
qbtp8482tv
111.11.111.111
bc644ba2501c
MF5601T_AMD-NDF
(null)
qbtp8482tv
222.22.222.222
704fb8f3e4e1
MF5601T_AMD-NDF
(null)

您可以使用过滤器排除空值:

where rtrim(ltrim(item, chr(32)||chr(10)), chr(10)||chr(32)) is not null;

给出 8 行:

ITEM
--------------
qbtp8482tv
111.11.111.111
bc644ba2501c
MF5601T_AMD-NDF
qbtp8482tv
222.22.222.222
704fb8f3e4e1
MF5601T_AMD-NDF

如果您想将它们插入到表格中,只需将insert into your_table (your_column) 放入select ...

db<>fiddle

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-13
    • 1970-01-01
    相关资源
    最近更新 更多