如何提取oracle中包含名称空间的XML数据
查询: 试试这个:如何提取oracle中包含名称空间的XML数据,xml,oracle,Xml,Oracle,查询: 试试这个: select * from xmltable(XMLNAMESPACES('http://test/asdf/bean' as "bean", default 'http://example.org/SCL/CommonTypes') , '/bean:TransactionData/TransactionRequest/CustomerId' passing xmltype('<ns:TransactionData xmlns:ns="http://test/
select * from xmltable(XMLNAMESPACES('http://test/asdf/bean' as "bean",
default 'http://example.org/SCL/CommonTypes') , '/bean:TransactionData/TransactionRequest/CustomerId'
passing xmltype('<ns:TransactionData xmlns:ns="http://test/asdf/bean" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns:TransactionData">
<TransactionRequest xmlns:nste="http://pegasus/component/payment/bean" xsi:type="nste:bankTransferRequest">
<CustomerId>0001</CustomerId>
<Account>12332131321331</Account>
<Currency>MMK</Currency>
<Reference>83550 test</Reference>
</TransactionRequest>
</ns:TransactionData>'));
如果要使用bean作为名称空间前缀:
select t.* from xmltable(XMLNAMESPACES('http://test/asdf/bean' as "ns")
,'//ns:TransactionData/TransactionRequest/CustomerId'
passing xmltype('<ns:TransactionData xmlns:ns="http://test/asdf/bean" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns:TransactionData">
<TransactionRequest xmlns:nste="http://pegasus/component/payment/bean" xsi:type="nste:bankTransferRequest">
<CustomerId>0001</CustomerId>
<Account>12332131321331</Account>
<Currency>MMK</Currency>
<Reference>83550 test</Reference>
</TransactionRequest>
</ns:TransactionData>')) as t
使用Oracle 12.1和SQLplus的输出示例
select t.* from xmltable(XMLNAMESPACES('http://test/asdf/bean' as "bean")
,'//bean:TransactionData/TransactionRequest/CustomerId'
passing xmltype('<ns:TransactionData xmlns:ns="http://test/asdf/bean" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns:TransactionData">
<TransactionRequest xmlns:nste="http://pegasus/component/payment/bean" xsi:type="nste:bankTransferRequest">
<CustomerId>0001</CustomerId>
<Account>12332131321331</Account>
<Currency>MMK</Currency>
<Reference>83550 test</Reference>
</TransactionRequest>
</ns:TransactionData>')) as t
请在您的问题中添加更多详细信息。例如,什么不起作用。删除此项,默认值'http://example.org/SCL/CommonTypes'. 这里不需要它。我在Oracle 12c数据库中有一个表,其中包含一个XML类型的列,如上面的示例XML。但当我检索时,如上面的查询。它不能返回任何数据,也可以尝试选择EXTRACTVALUExmltypeXMLField,'/ns/:TransactionData/TransactionRequest/Field[@key=CustomerId]'MyTable中的CustomerId也是返回空白字段。bean命名空间存在于XML中。它只是有一个不同的前缀。前缀不需要匹配,URI是。关于默认名称空间,您是对的。为什么要使用不同的前缀?谢谢,我尝试使用bean名称空间进行查询。但它也不会返回任何结果。请建议我。谢谢发布的查询返回CustomerId。“你不喜欢它的什么地方?”雷内,你为什么不喜欢?这没什么区别。前缀完全是短暂的。OP的代码在这方面是完美的。
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL> select t.* from xmltable(XMLNAMESPACES('http://test/asdf/bean' as "bean")
2 ,'//bean:TransactionData/TransactionRequest/CustomerId'
3 passing xmltype('<ns:TransactionData xmlns:ns="http://test/asdf/bean" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns:TransactionData">
4 <TransactionRequest xmlns:nste="http://pegasus/component/payment/bean" xsi:type="nste:bankTransferRequest">
5 <CustomerId>0001</CustomerId>
6 <Account>12332131321331</Account>
7 <Currency>MMK</Currency>
8 <Reference>83550 test</Reference>
9 </TransactionRequest>
10 </ns:TransactionData>')) as t;
COLUMN_VALUE
--------------------------------------------------------------------------------
<CustomerId>0001</CustomerId>