首先,請張貼有效的XML,因爲您顯示的內容看起來像是從瀏覽器中刮取的屏幕,並且缺少結尾標記並且具有無效字符。如果您的xml具有名稱空間引用,那麼您需要將它們包含在XPath中,並作爲extract()函數的參數。這裏有一個例子:
with fnd_soa_body_piece as (
select xmltype(
'<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<SOAP-ENV:Body>
<tns1:InputParameters xmlns:tns1="http://xmlns.oracle.com/apps/gl/soaprovider/plsql/geas_gl_journal_pkg/geas_get_gl_data/">
<tns1:P_BATCH_TBL>
<tns1:P_BATCH_TBL_ITEM>
<tns1:BATCH_ID>85380</tns1:BATCH_ID>
</tns1:P_BATCH_TBL_ITEM>
<tns1:P_BATCH_TBL_ITEM>
<tns1:BATCH_ID>85345</tns1:BATCH_ID>
</tns1:P_BATCH_TBL_ITEM>
<tns1:P_BATCH_TBL_ITEM>
<tns1:BATCH_ID>85364</tns1:BATCH_ID>
</tns1:P_BATCH_TBL_ITEM>
<tns1:P_BATCH_TBL_ITEM>
<tns1:BATCH_ID>85356</tns1:BATCH_ID>
</tns1:P_BATCH_TBL_ITEM>
<tns1:P_BATCH_TBL_ITEM>
<tns1:BATCH_ID>85374</tns1:BATCH_ID>
</tns1:P_BATCH_TBL_ITEM>
<tns1:P_BATCH_TBL_ITEM>
<tns1:BATCH_ID>85358</tns1:BATCH_ID>
</tns1:P_BATCH_TBL_ITEM>
</tns1:P_BATCH_TBL>
</tns1:InputParameters>
</SOAP-ENV:Body>
</SOAP-ENV:Header>
</SOAP-ENV:Envelope>') body from dual
)
select extract(body,'/SOAP-ENV:Envelope/SOAP-ENV:Header/SOAP-ENV:Body/tns1:InputParameters/tns1:P_BATCH_TBL/tns1:P_BATCH_TBL_ITEM/tns1:BATCH_ID',
' xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tns1="http://xmlns.oracle.com/apps/gl/soaprovider/plsql/geas_gl_journal_pkg/geas_get_gl_data/"').getStringVal()
from fnd_soa_body_piece
更新:
返回的結果爲一個SQL數據集,你需要使用XMLTABLE函數,如:
with fnd_soa_body_piece as (
select xmltype(
'<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<SOAP-ENV:Body>
<tns1:InputParameters xmlns:tns1="http://xmlns.oracle.com/apps/gl/soaprovider/plsql/geas_gl_journal_pkg/geas_get_gl_data/">
<tns1:P_BATCH_TBL>
<tns1:P_BATCH_TBL_ITEM>
<tns1:BATCH_ID>85380</tns1:BATCH_ID>
</tns1:P_BATCH_TBL_ITEM>
<tns1:P_BATCH_TBL_ITEM>
<tns1:BATCH_ID>85345</tns1:BATCH_ID>
</tns1:P_BATCH_TBL_ITEM>
<tns1:P_BATCH_TBL_ITEM>
<tns1:BATCH_ID>85364</tns1:BATCH_ID>
</tns1:P_BATCH_TBL_ITEM>
<tns1:P_BATCH_TBL_ITEM>
<tns1:BATCH_ID>85356</tns1:BATCH_ID>
</tns1:P_BATCH_TBL_ITEM>
<tns1:P_BATCH_TBL_ITEM>
<tns1:BATCH_ID>85374</tns1:BATCH_ID>
</tns1:P_BATCH_TBL_ITEM>
<tns1:P_BATCH_TBL_ITEM>
<tns1:BATCH_ID>85358</tns1:BATCH_ID>
</tns1:P_BATCH_TBL_ITEM>
</tns1:P_BATCH_TBL>
</tns1:InputParameters>
</SOAP-ENV:Body>
</SOAP-ENV:Header>
</SOAP-ENV:Envelope>') body from dual
)
select t.batch_id
from fnd_soa_body_piece,
xmltable(xmlnamespaces(
'http://schemas.xmlsoap.org/soap/encoding/' as "SOAP-ENC",
'http://schemas.xmlsoap.org/soap/envelope/' as "SOAP-ENV",
'http://xmlns.oracle.com/apps/gl/soaprovider/plsql/geas_gl_journal_pkg/geas_get_gl_data/' as "tns1"),
'/SOAP-ENV:Envelope/SOAP-ENV:Header/SOAP-ENV:Body/tns1:InputParameters/tns1:P_BATCH_TBL/tns1:P_BATCH_TBL_ITEM/tns1:BATCH_ID'
passing fnd_soa_body_piece.body columns batch_id number(10) PATH 'text()') t
謝謝你的文章! ! 1.它只適用於xml數據中沒有第一行xml'<?xml version ='1.0'encoding ='UTF-8'?>'我該如何處理?第二件事是用batch_id標籤以xml格式返回值。我怎樣才能單獨獲取數據? –
這就是輸出結果:Example:' 85380 tns1:BATCH_ID > 85345 tns1:BATCH_ID>' –
請參閱答案中的更新。我對XML處理指令沒有任何問題。 – OldProgrammer