我有下面的XML消息:
<Message xmlns="http://test.org">
<Request Promotion="MULANN">
<ExpireDate>23/10/2020 07:10</ExpireDate>
<Entries>
<Entry>
<Product>
<Product Product="T1" />
</Product>
<Payment>
<Privacy>N</Privacy>
</Payment>
</Entry>
<Entry>
<Product>
<Product Product="T2" />
</Product>
<Payment>
<Privacy>N</Privacy>
</Payment>
</Entry>
<Entry>
<Product>
<Product Product="T3" />
</Product>
<Payment>
<Privacy>Y</Privacy>
</Payment>
</Entry>
</Entries>
</Request>
</Message>
对于这个xml消息,我有三倍的xml标记Privacy
我如何才能在不获取错误的情况下为所有人获得独特的隐私价值?。
现在我使用下面包含错误的查询:
select distinct x.Promotion, x.Privacy
from TableName a
cross join XMLTable(XMLNAMESPACES('http://test.org' AS "XML"),
'/XML:Message' passing xmltype(xml_info) columns
Promotion VARCHAR2(20) path 'XML:Request/@Promotion'
Iban_TABD CHAR(1) path 'XML:Request/XML:Entries/XML:Entry/XML:Payment/XML:Privacy')x
我想要这样的东西:
Promotion Privacy
MULANN N
MULANN Y
问题是XML有多层嵌套。您可以通过链接XMLTABLEs来解决这个问题。
如果嵌套子级中并非所有信息都可用,则外部联接会有所帮助。
SELECT DISTINCT
promotion,
privacy
FROM TableName,
XMLTABLE( XMLNAMESPACES( DEFAULT 'http://test.org'),
'/Message' PASSING XMLTYPE(xml_info)
COLUMNS promotion VARCHAR2(20) PATH 'Request/@Promotion',
entries XMLTYPE PATH 'Request/Entries/Entry'
) x1
LEFT OUTER JOIN (
XMLTABLE( XMLNAMESPACES( DEFAULT 'http://test.org'),
'/Entry' PASSING x1.entries
COLUMNS privacy VARCHAR2(1) PATH 'Payment/Privacy'
)) x2
ON 1=1;