EXTRACTVALUE
has been deprecated for some time. You should be using XQuery, in this case with a single simple path using XMLQuery; plus you need to refer to the namespace ns1
, and you are ignoring the top-level node validateAccountResponse
:
with t (l_resp_xml) as (
select xmltype('<ns1:validateAccountResponse
xmlns:ns1="https://ws.hyphen.co.za/accountvalidation2">
<return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="tns:WebService_AccountValidation_Response">
<reference xsi:type="xsd:string">TLPM165U2876100975</reference>
<branchCode xsi:type="xsd:string">187646</branchCode>
<bankName xsi:type="xsd:string">NED:NEDBANK LTD RSA</bankName>
<branchName xsi:type="xsd:string">NEDBANK BRITS</branchName>
<accountNumber xsi:type="xsd:string">00000002876100975</accountNumber>
<accountType xsi:type="xsd:string">2</accountType>
<errorCode xsi:type="xsd:string">0</errorCode>
<resultCode xsi:type="xsd:string">0000</resultCode>
<resultMessage xsi:type="xsd:string"/>
<checkSum xsi:type="xsd:string">db8d375002ca1e62ab4e8696c480df12d7e10293a29ba1a0dc99868d18 aa2c7e</checkSum>
</return></ns1:validateAccountResponse>') from dual
)
SELECT XMLQuery('declare namespace ns1 = "https://ws.hyphen.co.za/accountvalidation2"; (::)
/ns1:validateAccountResponse/return/bankName/text()'
PASSING l_resp_xml RETURNING CONTENT) AS bankName
FROM t;
BANKNAME
--------------------------------------------------------------------------------
NED:NEDBANK LTD RSA
Or with your PL/SQL value:
SELECT CAST(XMLQuery('declare namespace ns1 = "https://ws.hyphen.co.za/accountvalidation2"; (::)
/ns1:validateAccountResponse/return/bankName/text()'
PASSING l_resp_xml RETURNING CONTENT) AS VARCHAR2(30))
INTO l_bank_name
FROM dual;
You could also use an XMLTable to extract multiple values more easily, particularly when you're getting multiple XMLType values from rows in a table:
with t (l_resp_xml) as (
select xmltype('<ns1:validateAccountResponse
xmlns:ns1="https://ws.hyphen.co.za/accountvalidation2">
<return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="tns:WebService_AccountValidation_Response">
<reference xsi:type="xsd:string">TLPM165U2876100975</reference>
<branchCode xsi:type="xsd:string">187646</branchCode>
<bankName xsi:type="xsd:string">NED:NEDBANK LTD RSA</bankName>
<branchName xsi:type="xsd:string">NEDBANK BRITS</branchName>
<accountNumber xsi:type="xsd:string">00000002876100975</accountNumber>
<accountType xsi:type="xsd:string">2</accountType>
<errorCode xsi:type="xsd:string">0</errorCode>
<resultCode xsi:type="xsd:string">0000</resultCode>
<resultMessage xsi:type="xsd:string"/>
<checkSum xsi:type="xsd:string">db8d375002ca1e62ab4e8696c480df12d7e10293a29ba1a0dc99868d18 aa2c7e</checkSum>
</return></ns1:validateAccountResponse>') from dual
)
SELECT x.reference, x.bankname, x.branchCode
FROM t
CROSS JOIN XMLTABLE(
XMLNAMESPACES('https://ws.hyphen.co.za/accountvalidation2' as "ns1"),
'/ns1:validateAccountResponse/return'
PASSING t.l_resp_xml
COLUMNS reference VARCHAR2(20) PATH 'reference',
bankName VARCHAR2(30) PATH 'bankName',
branchCode NUMBER PATH 'branchCode'
) x;
REFERENCE BANKNAME BRANCHCODE
-------------------- ------------------------------ ----------
TLPM165U2876100975 NED:NEDBANK LTD RSA 187646
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…