CREATE TABLE xml_test
(
id NUMBER DEFAULT 1 ,
xml_text VARCHAR2 (4000 BYTE),
ts_update DATE DEFAULT SYSDATE
)
SET DEFINE OFF;
(ID, XML_TEXT, TS_UPDATE)
Values
(2, '<page>
<id>72054439</id>
<redactions>
<redaction>
<id>0</id>
<privileges>
<privilege>
<id>164</id>
<Code>ACP</Code>
</privilege>
<privilege>
<id>165</id>
<Code>AWPD</Code>
</privilege>
</privileges>
</redaction>
<redaction>
<id>0</id>
<privileges>
<privilege>
<id>164</id>
<Code>ACP</Code>
</privilege>
<privilege>
<id>165</id>
<Code>AWPD</Code>
</privilege>
</privileges>
</redaction>
</redactions>
</page>', SYSDATE);
COMMIT;
This Query
SELECT x1.id page_id, x2.id privilege_id, x2.code privilege_code
FROM xml_test t,
XMLTABLE ('/page'
PASSING xmltype (t.xml_text)
COLUMNS
id NUMBER PATH './id',
xml_privilege XMLTYPE PATH '/page/redactions/redactio
) x1,
XMLTABLE ('/privileges/privilege'
PASSING x1.xml_privilege
COLUMNS
id NUMBER PATH './id',
code VARCHAR (5) PATH './Code'
) x2
WHERE t.id = 2
would return PAGE_ID PRIVILEGE_ID PRIVILEGE_CODE
72054439 164 ACP
72054439 165 AWPD
72054439 164 ACP
72054439 165 AWPD
No comments:
Post a Comment