【问题标题】:Oracle extractValue returns invalid tokenOracle extractValue 返回无效令牌
【发布时间】:2019-02-15 15:06:41
【问题描述】:

我有这个查询在这个提取值上失败

EXTRACTVALUE(xmltype(REQUEST), '/soapenv:Envelope/soapenv:Body/ns2:getCustomerRequestRetrieve/ns2:requestHeader/ns5:referenceID', 'xmlns:soapenv:http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns8="ca/bell/oms/autotype/customerrequestretrieve" xmlns:ns2="ca/bell/oms/autotype/customerrequestretrieve"') RequestReferenceID

我在某个地方设置了错误的路径。你能告诉我哪里出错了吗 实际的 XML 是

<soapenv:Envelope
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <ns2:getCustomerRequestRetrieve xmlns = "ca/bell/oms/autotype/omscommonresponse"
            xmlns:ns5 = "sa/cell/oms/autotype/omscommonrequest"
            xmlns:ns2 = "sa/cell/oms/autotype/customerrequestretrieve"
            xmlns:ns3 = "sa/cell/oms/autotype/omscommon"
            xmlns:ns4 = "sa/cell/oms/customerprofile">
            <ns2:requestHeader>
                <ns5:customerInteractionType>CustomerNotification</ns5:customerInteractionType>
                <ns5:serviceRequestUserId>null</ns5:serviceRequestUserId>
                <ns5:serviceConsumer>khg</ns5:serviceConsumer>
                <ns5:serviceRequestTimestamp>2019-02-05T03:50:12.000-05:00</ns5:serviceRequestTimestamp>
                <ns5:language>English</ns5:language>
                <ns5:referenceID>Tjutrf7T78H4</ns5:referenceID>
                <ns5:transactionIdentifier>eed7ffe0-da22-498f-9913-c2279d1549356612606</ns5:transactionIdentifier>
            </ns2:requestHeader>
            <ns2:searchCriteria>
                <ns2:requestIdentifier>
                    <ns2:orderNumber>TTjutrf7T8H4</ns2:orderNumber>
                </ns2:requestIdentifier>
            </ns2:searchCriteria>
            <ns2:filterCriteria>
                <ns2:fullOrderDetail>ContactOnly</ns2:fullOrderDetail>
            </ns2:filterCriteria>
        </ns2:getCustomerRequestRetrieve>
    </soapenv:Body>
</soapenv:Envelope>

在此处输入代码

【问题讨论】:

    标签: sql xml oracle


    【解决方案1】:

    你在命名空间声明中有错误。

    EXTRACTVALUE(REQUEST, '/soapenv:Envelope/soapenv:Body/ns2:getCustomerRequestRetrieve/ns2:requestHeader/ns5:referenceID'
    ,'xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:ns2="sa/cell/oms/autotype/customerrequestretrieve"
    xmlns:ns5="sa/cell/oms/autotype/omscommonrequest"
    ') RequestReferenceID
    

    此外,EXTRACTVALUE 函数已被弃用。 Replacemnet 是 xmlquery,xmltable。

    select xmlcast(xmlquery('declare namespace soapenv="http://schemas.xmlsoap.org/soap/envelope/";
    declare namespace ns2="sa/cell/oms/autotype/customerrequestretrieve";
    declare namespace ns5="sa/cell/oms/autotype/omscommonrequest";
    /soapenv:Envelope/soapenv:Body/ns2:getCustomerRequestRetrieve/ns2:requestHeader/ns5:referenceID/text()' passing xmltype(request) returning content) as varchar2(100)) from ....; 
    

    【讨论】: