SELECT * FROM v$version; *Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production PL/SQL Release 12.1.0.2.0 - Production "CORE 12.1.0.2.0 Production" TNS for Linux: Version 12.1.0.2.0 - Production NLSRTL Version 12.1.0.2.0 - Production*
I have sample Query with XML like below:
with t(xml) as ( select xmltype( '<SSO_XML xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" TimeStamp="2020-08-05T21:57:23Z" Target="Production" Version="1.0" TransactionIdentifier="PLAN_A" SequenceNmbr="123456" xmlns="http://www.w3.org/2001/XMLSchema"> <PlanCode PlanCodeCode="CHOICE"> <S_DAYS FARE="10" Start="2020-08-07" End="2020-10-30" Mon="true" Tue="true" Weds="true" Thur="true" Fri="true" Sat="true" Sun="true"> <STUDENT> <DIVISION ORIGINAL="150.05" Code="Flat" S_CODE="1" /> <DIVISION ORIGINAL="150.05" Code="Flat" S_CODE="2" /> </STUDENT> </S_DAYS> </PlanCode> </SSO_XML>') from dual ) select h.PlanCodeCode ,b.Original ,b.code ,b.s_code from t cross join xmltable(xmlnamespaces(default 'http://www.w3.org/2001/XMLSchema'), '/SSO_XML' passing t.xml columns PlanCodeCode varchar2(100) path './PlanCode/@PlanCodeCode', attributes xmltype path './PlanCode' ) h cross join xmltable(xmlnamespaces(default 'http://www.w3.org/2001/XMLSchema'), 'PlanCode/S_DAYS/STUDENT/DIVISION' passing h.attributes columns ORIGINAL number path '@ORIGINAL', Code varchar2(100) path '@Code', S_CODE number path '@S_CODE' ) b;
Output:
I am trying to fetch the values below within the query or a new query: Is there any way to do that? Any help / direction appreciated.
Advertisement
Answer
You just have to complete your first XMLTABLE query (h) in this way:
target varchar2(100) path '/SSO_XML/@Target', transactionId varchar2(100) path '/SSO_XML/@TransactionIdentifier'