I got a sql from an Oracle table with a XMLTYPE column.
The Xml has a tag with a value '2' and in the same xml there is the list with value/label pairs like this:
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<characteristics>
<motor>
<fuel>2</fuel>
</motor>
</characteristics>
<ValuesList>
<CarValues>
<CarValue>
<value>1</value>
<label>Diesel</label>
</CarValue>
<CarValue>
<value>2</value>
<label>Unleaded petrol</label>
</CarValue>
</CarValues>
</ValuesList>
</Root>
With extract() or extractValue() functions it's easy to get the value for tag with any of these staments a, b
SELECT extract(t.xmlColumn, '//fuel/text()').getStringVal() a,
extractValue(t.xmlColumn, '//fuel') b
FROM Table t
The problem is I want to get the label text for value '2' from Valueslist 'Unleaded petrol'
I try to get that value with a XPATH expresion like this:
extractValue(t.xmlColumn, '//CarValue/label[../value=//fuel]')
The XPATH has been evaluated with Notepad XML Tools and it works, but there's no way to get any result. it's always null.
Any idea how to achive this? I don't know how to use XMLTABLE or any other solution to this case.
You need to include the /text() part in your attempt:
SELECT
extract(t.xmlColumn,'//fuel/text()').getStringVal() a
,extractValue(t.xmlColumn,'//fuel') b
,extractValue(t.xmlColumn, '//CarValue/label[../value=//fuel/text()]') c
FROM your_table t
A
B
C
2
2
Unleaded petrol
In your version you're trying to match a label with a value of the node <fuel>2</fuel>, not the text within than node, 2.
Both extract() and extractValue() are deprecated, so you could use XMLQuery instead:
SELECT
XMLQuery('//fuel/text()' passing xmlColumn returning content) a
,XMLQuery('//CarValue/label[../value=//fuel/text()]/text()' passing xmlColumn returning content) a
FROM your_table t
A
A
2
Unleaded petrol
Or with XMLTable();
SELECT x.a, x.b
FROM your_table t
CROSS APPLY XMLTable(
'/'
passing t.xmlColumn
columns a number path '//fuel',
b varchar2(30) path '//CarValue/label[../value=//fuel/text()]'
) x
A
B
2
Unleaded petrol
fiddle
If your version of Oracle isn't working with the node traversal using ../ then you could do it the hard way by getting the fuel value and all the id/label pairs with separate XMLTable calls, and then filtering those that match:
SELECT x1.fuel, x2.label
FROM your_table t
CROSS JOIN XMLTable(
'//fuel'
passing t.xmlColumn
columns fuel number path '.'
) x1
JOIN XMLTable(
'//CarValue'
passing t.xmlColumn
columns value number path 'value',
label varchar2(30) path 'label'
) x2 ON x2.value = x1.fuel
FUEL
LABEL
2
Unleaded petrol
fiddle
All solutions Alex Poole gave are accepted solutions for the question case title where "a value/label list within same XML" is present.
Just for information, in case "a value/label list is not present in the same XML", solution is create an auxiliary XMLTable with a XMLTYPE field and the value/label list XML in it.
SELECT x1.fuel, x2.labelFROM your_table t
CROSS JOIN XMLTable(
'//fuel'
passing t.xmlColumn
columns fuel number path '.'
) x1
LEFT JOIN XMLTable(
'//CarValue'
passing
(SELECT XMLTYPE('
<ValuesList>
<CarValues>
<CarValue>
<value>1</value>
<label>Diesel</label>
</CarValue>
<CarValue>
<value>2</value>
<label>Unleaded petrol</label>
</CarValue>
</CarValues>
</ValuesList>
') FROM dual)
columns value number path 'value',
label varchar2(30) path 'label'
) x2 ON x2.value = x1.fuel
I have the following SQL :
with q1 (Tdata) as (
SELECT XMLtype(transportdata, nls_charset_id('AL32UTF8'))
from bph_owner.paymentinterchange pint
where --PINT.INCOMING = 'T' and
PINT.TRANSPORTTIME >= to_date('2022-08-10', 'yyyy-mm-dd')
and pint.fileformat = 'pain.001.001.03'
)
--select XMLQuery('//*:GrpHdr/*:InitgPty/Nm/text()'
select tdata, XMLQuery('//*:GrpHdr/*:CtrlSum/text()'
passing Tdata
returning content).getstringval()
,
XMLQuery('//*:GrpHdr/*:MsgId/text()'
passing Tdata
returning content).getstringval()
from q1;
This works but for the InitgPty/Nm/ it doesn't - anybody know how I can extract this information?
Please be gentle as I don't work with XML much.
Thanks
Based on sample data from a previous question and other relating to this XML schema, it appears you just need to wildcard the namespace for Nm node, as well as its parents:
'//*:GrpHdr/*:InitgPty/*:Nm/text()'
so the query could become:
with q1 (Tdata) as (
SELECT XMLtype(transportdata, nls_charset_id('AL32UTF8'))
from paymentinterchange pint
where --PINT.INCOMING = 'T' and
PINT.TRANSPORTTIME >= to_date('2022-08-10', 'yyyy-mm-dd')
and pint.fileformat = 'pain.001.001.03'
)
select
XMLQuery('//*:GrpHdr/*:InitgPty/*:Nm/text()'
passing Tdata
returning content).getstringval() as nm
,
XMLQuery('//*:GrpHdr/*:CtrlSum/text()'
passing Tdata
returning content).getstringval() as ctrlsum
,
XMLQuery('//*:GrpHdr/*:MsgId/text()'
passing Tdata
returning content).getstringval() as msgig
from q1;
But if you're pulling multiple values out of the same document then it's simpler to use XMLTable rather than multiple XMLQuery calls:
select x.nm, x.ctrlsum, x.msgid
from paymentinterchange pint
cross apply XMLTable(
'//*:GrpHdr'
passing XMLtype(pint.transportdata, nls_charset_id('AL32UTF8'))
columns nm varchar2(50) path '*:InitgPty/*:Nm',
ctrlsum number path '*:CtrlSum',
msgid varchar2(50) path '*:MsgId'
) x
where pint.transporttime >= date '2022-08-10'
and pint.fileformat = 'pain.001.001.03';
db<>fiddle with data adapted from a previous question.
Before Oracle 12c you can use cross join instead of cross apply. I don't think it would make a difference in later versions either, that just seems to be my default now...
select x.nm, x.ctrlsum, x.msgid
from paymentinterchange pint
cross join XMLTable(
'//*:GrpHdr'
passing XMLtype(pint.transportdata, nls_charset_id('AL32UTF8'))
columns nm varchar2(50) path '//*:InitgPty/*:Nm',
ctrlsum number path '//*:CtrlSum',
msgid varchar2(50) path '//*:MsgId'
) x
where pint.transporttime >= date '2022-08-12'
and pint.fileformat = 'pain.001.001.03';
db<>fiddle showing it in 11.2.0.2, where it seems to need the // at the start of all the paths, including in the columns clause - those aren't needed in later versions, but here it returns nulls without them.
I am trying to parse xml in my oracle DB to return individual rows. I have different xpath the ,downPaymentSourceType INT PATH '/downPaymentSource/downPaymentSourceTypeDd' and ,DownpaymentAmount INT PATH '/downPaymentSource/amount' are returning nulls. How do I handle this to provide accurate results. Thanks
WITH t( xml ) AS
(
SELECT XMLType('<loanApplication xmlns="http://www.abcdef.com/Schema/FCX/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<deal>
<applicationDate>2017-01-10T16:15:00-05:00</applicationDate>
<applicationId>QA-8899</applicationId>
<combinedGds>0.13055</combinedGds>
<combinedLtv>1.8</combinedLtv>
<combinedTds>10.2714</combinedTds>
<dealPurposeDd>2</dealPurposeDd>
<dealTypeDd>0</dealTypeDd>
<downPaymentSource>
<amount>25000.0</amount>
<downPaymentSourceTypeDd>1</downPaymentSourceTypeDd>
<description>aasdadsf</description>
</downPaymentSource>
<downPaymentSource>
<amount>25000.0</amount>
<downPaymentSourceTypeDd>6</downPaymentSourceTypeDd>
<description>wrewertwerewrt</description>
</downPaymentSource>
<downPaymentSource>
<amount>50000.0</amount>
<downPaymentSourceTypeDd>10</downPaymentSourceTypeDd>
<description>second and thirs</description>
</downPaymentSource>
<estimatedClosingDate>2017-12-05T00:00:00-05:00</estimatedClosingDate>
<financingWaiverDate>2017-01-04T00:00:00-05:00</financingWaiverDate>
<refiImprovementAmount>10000.0</refiImprovementAmount>
<refiImprovementsDesc>roof</refiImprovementsDesc>
<refiImprovementsFlag>Y</refiImprovementsFlag>
<refiPurpose>refi purpose</refiPurpose>
<taxPayorDd>1</taxPayorDd>
<additionalData dataType="String" name="firmLicenseRegistrationNumber" xmlns:t="http://www.abcdef.com/Schema/FCX/1">C000312345</additionalData>
</deal>
<applicantGroup>
<applicantGroupTypeDd>0</applicantGroupTypeDd>
<applicant>
<employmentHistory>
<employerName>employer name</employerName>
<employmentHistoryStatusDd>0</employmentHistoryStatusDd>
<employmentHistoryTypeDd>0</employmentHistoryTypeDd>
<income>
<annualIncomeAmount>200000.0</annualIncomeAmount>
<incomeAmount>200000.0</incomeAmount>
<incomePeriodDd>0</incomePeriodDd>
<incomeTypeDd>6</incomeTypeDd>
</income>
</employmentHistory>
<asset>
<assetDescription>qwerqwer</assetDescription>
<assetTypeDd>0</assetTypeDd>
<assetValue>1111.0</assetValue>
</asset>
<liability>
<broker>
<creditLimit>9283.0</creditLimit>
<liabilityAmount>9999999.8</liabilityAmount>
<liabilityMonthlyPayment>299999.99</liabilityMonthlyPayment>
<liabilityTypeDd>2</liabilityTypeDd>
</broker>
</liability>
</applicant>
<applicant>
<employmentHistory>
<income>
<annualIncomeAmount>150000.0</annualIncomeAmount>
<incomeAmount>150000.0</incomeAmount>
<incomeDescription>income description</incomeDescription>
<incomePeriodDd>0</incomePeriodDd>
<incomeTypeDd>6</incomeTypeDd>
</income>
</employmentHistory>
</applicant>
</applicantGroup>
</loanApplication>')
FROM dual
)
SELECT
JSON_OBJECT (
KEY 'dealClosingDate' value x.DealClosingDate
,KEY 'dealPurpose' value x.dealPurpose
,KEY 'combinedGds' value x.combinedGds
,KEY 'combinedTds' value x.combinedTds
,KEY 'combinedLtv' value x.combinedLtv
,KEY 'downpaymentAmount' value x.DownpaymentAmount
,KEY 'combinedAssets' value y.CombinedAssets
,KEY 'combinedLiabilities' value y.CombinedLiabilities
,KEY 'combinedIncome' value y.CombinedIncome
,KEY 'downPaymentSourceType' value x.downPaymentSourceType
,KEY 'sourceAmount' value x.DownpaymentAmount
) Deal
FROM t,
XMLTABLE(XMLNAMESPACES(DEFAULT 'http://www.abcdef.com/Schema/FCX/1'), '/loanApplication/deal'
PASSING xml
COLUMNS
DealClosingDate timestamp with time zone PATH 'estimatedClosingDate'
,dealPurpose INT PATH 'dealPurposeDd'
,combinedGds INT PATH 'combinedGds'
,combinedTds INT PATH 'combinedTds'
,combinedLtv INT PATH 'combinedLtv'
,downPaymentSourceType INT PATH '/downPaymentSource/downPaymentSourceTypeDd'
,DownpaymentAmount INT PATH '/downPaymentSource/amount'
) x,
XMLTABLE(XMLNAMESPACES(DEFAULT 'http://www.abcdef.com/Schema/FCX/1'), '/loanApplication/applicantGroup/applicant'
PASSING xml
COLUMNS
CombinedLiabilities INT PATH 'liability/broker/liabilityAmount'
,CombinedIncome INT PATH 'employmentHistory/income/incomeAmount'
,CombinedAssets INT PATH 'asset/assetValue'
) y
You are cross-joining the base table and the two XMLTable calls. Your second XMLTable looks for applicantGroup nodes, and there aren't any in this XML document, so that gets now rows; and therefore the query overall returns no rows either.
If you change the second (implicit) cross join to outer apply then you'll still see the data found by the first XMLtable. It's unclear if there will always be a deal node, but you can make the first join an outer apply too.
...
FROM t
OUTER APPLY
XMLTABLE(XMLNAMESPACES(DEFAULT 'http://www.abcdef.com/Schema/FCX/1'), '/loanApplication/deal'
PASSING xml
COLUMNS
DealClosingDate timestamp with time zone PATH 'estimatedClosingDate'
,dealPurpose INT PATH 'dealPurposeDd'
,combinedGds INT PATH 'combinedGds'
,combinedTds INT PATH 'combinedTds'
,combinedLtv INT PATH 'combinedLtv'
,downPaymentSourceType INT PATH '/downPaymentSource/downPaymentSourceTypeDd'
,DownpaymentAmount INT PATH '/downPaymentSource/amount'
) x
OUTER APPLY
XMLTABLE(XMLNAMESPACES(DEFAULT 'http://www.abcdef.com/Schema/FCX/1'), '/loanApplication/applicantGroup/applicant'
PASSING xml
COLUMNS
CombinedLiabilities INT PATH 'liability/broker/liabilityAmount'
,CombinedIncome INT PATH 'employmentHistory/income/incomeAmount'
,CombinedAssets INT PATH 'asset/assetValue'
) y
DEAL
{"dealClosingDate":"2017-12-05T00:00:00.000000-05:00","dealPurpose":2,"combinedGds":0,"combinedTds":10,"combinedLtv":2,"downpaymentAmount":null,"combinedAssets":null,"combinedLiabilities":null,"combinedIncome":null,"downPaymentSourceType":null,"sourceAmount":null}
db<>fiddle
(I changed the dealClosingDate data type because... well, I could, and it didn't really look right as a string; but as it ends up as a string in the JSON anyway it's a bit moot.)
Depending on whether you can have multiple (or zero) deal nodes and/or multiple (or zero) applicantGroup nodes - presumably groups can have multiple child nodes - you might be able to structure the XMLTables a bit differently, but it depends on the data and what you want to see.
from your result, you can see that downPaymentSourceType and downpaymentAmount are retuning nulls which is not the case in the XML
That's because the path you are using for those starts with /downPaymentSource/... which doesn't exist within the XPath; and if you did ./downPaymentSource/... or just /downPaymentSource/... you would get a "expected singleton sequence - got multi-item sequence" error.
You can extract the collection of those downPaymentSource nodes as an XMLType, and then use another XMLTable to expand those too:
FROM t
OUTER APPLY
XMLTABLE(XMLNAMESPACES(DEFAULT 'http://www.abcdef.com/Schema/FCX/1'), '/loanApplication/deal'
PASSING xml
COLUMNS
DealClosingDate timestamp with time zone PATH 'estimatedClosingDate'
,dealPurpose INT PATH 'dealPurposeDd'
,combinedGds INT PATH 'combinedGds'
,combinedTds INT PATH 'combinedTds'
,combinedLtv INT PATH 'combinedLtv'
,downPayments XMLType PATH 'downPaymentSource'
-- ,downPaymentSourceType INT PATH '/downPaymentSource/downPaymentSourceTypeDd'
-- ,DownpaymentAmount INT PATH '/downPaymentSource/amount'
) x
OUTER APPLY
XMLTABLE(
XMLNAMESPACES(DEFAULT 'http://www.abcdef.com/Schema/FCX/1'), '/downPaymentSource'
PASSING x.downPayments
COLUMNS
downPaymentSourceType INT PATH 'downPaymentSourceTypeDd'
,DownpaymentAmount INT PATH 'amount'
) y
OUTER APPLY
XMLTABLE(XMLNAMESPACES(DEFAULT 'http://www.abcdef.com/Schema/FCX/1'), '/loanApplication/applicantGroup/applicant'
PASSING xml
COLUMNS
CombinedLiabilities INT PATH 'liability/broker/liabilityAmount'
,CombinedIncome INT PATH 'employmentHistory/income/incomeAmount'
,CombinedAssets INT PATH 'asset/assetValue'
) z
DEAL
{"dealClosingDate":"2017-12-05T00:00:00.000000-05:00","dealPurpose":2,"combinedGds":0,"combinedTds":10,"combinedLtv":2,"downpaymentAmount":25000,"combinedAssets":1111,"combinedLiabilities":10000000,"combinedIncome":200000,"downPaymentSourceType":1,"sourceAmount":25000}
{"dealClosingDate":"2017-12-05T00:00:00.000000-05:00","dealPurpose":2,"combinedGds":0,"combinedTds":10,"combinedLtv":2,"downpaymentAmount":25000,"combinedAssets":null,"combinedLiabilities":null,"combinedIncome":150000,"downPaymentSourceType":1,"sourceAmount":25000}
{"dealClosingDate":"2017-12-05T00:00:00.000000-05:00","dealPurpose":2,"combinedGds":0,"combinedTds":10,"combinedLtv":2,"downpaymentAmount":25000,"combinedAssets":1111,"combinedLiabilities":10000000,"combinedIncome":200000,"downPaymentSourceType":6,"sourceAmount":25000}
{"dealClosingDate":"2017-12-05T00:00:00.000000-05:00","dealPurpose":2,"combinedGds":0,"combinedTds":10,"combinedLtv":2,"downpaymentAmount":25000,"combinedAssets":null,"combinedLiabilities":null,"combinedIncome":150000,"downPaymentSourceType":6,"sourceAmount":25000}
{"dealClosingDate":"2017-12-05T00:00:00.000000-05:00","dealPurpose":2,"combinedGds":0,"combinedTds":10,"combinedLtv":2,"downpaymentAmount":50000,"combinedAssets":1111,"combinedLiabilities":10000000,"combinedIncome":200000,"downPaymentSourceType":10,"sourceAmount":50000}
{"dealClosingDate":"2017-12-05T00:00:00.000000-05:00","dealPurpose":2,"combinedGds":0,"combinedTds":10,"combinedLtv":2,"downpaymentAmount":50000,"combinedAssets":null,"combinedLiabilities":null,"combinedIncome":150000,"downPaymentSourceType":10,"sourceAmount":50000}
db<>fiddle
That still might not be what you want though; you might be trying to get a JSON array of those values, and maybe of the applicants too - depends if you're expecting 1, 2, or 6 JSON docs from this example XML doc. However, if you do want different JSON and can't figure out how to get there then you would need to ask a new question about that.
I have below XML as data stored in 1 of the columns in my table. I want to extract all the data under VestingInfo, each source data should be a single column. I tried the below but it give not a valid identifier error
select plans.* from cth01.tablename pl, XMLTABLE(XMLNAMESPACES
('http://...' as "ns3", 'http:/...' as "ns4"),
'/CTHClob/ns3:OtherData/ns4:Participant/ns4:Plans' PASSING
xmltype(pl.rqst_info) COLUMNSNumber varchar2(20) path
'ns4:Number', Pin varchar2(20) path 'ns4:Pin') plans where
pl.prty_rqst_id = '';
XML looks like below
<?xml version="1.0"?><CTHClobType xmlns:ns2="http://... xmlns:ns4....>
--namespaces removed
<ns3:OtherData>
<ns4:Participant>
<ns4:Name>ALEXA MAKAILA JAVAVILLAGE</ns4:Name>
<ns4:PIN>4159505</ns4:PIN>
<ns4:PlanBalance>3497.15</ns4:PlanBalance>
<ns4:ForcedDistributionAmount>3497.15</ns4:ForcedDistributionAmount>
<ns4:ParticipantListType>Critical</ns4:ParticipantListType>
<ns4:Plans>
<ns4:Plan>
<ns4:Number>100178</ns4:Number>
<ns4:Name>CHILDRENS HOSPITAL OF PHIL. RETIREMENT SAVINGS PLAN - CSA</ns4:Name>
<ns4:Balance>3497.15</ns4:Balance>
<ns4:VestingInfo>
<ns4:DelayedVestingLite>false</ns4:DelayedVestingLite>
<ns4:DelayedVestingFull>true</ns4:DelayedVestingFull>
<ns4:VestingSourcesOnSingleSchedule>false</ns4:VestingSourcesOnSingleSchedule>
--The above 3 should be repeted for each source
<ns4:Sources>
<ns4:Source>
<ns4:SourceID>T</ns4:SourceID>
<ns4:SourceName>EMPLOYER MATCH</ns4:SourceName>
<ns4:VestedPercentage>50</ns4:VestedPercentage>
<ns4:VestedAmount>5647.94</ns4:VestedAmount>
<ns4:UnAdjustedVestedPercent>50</ns4:UnAdjustedVestedPercent>
<ns4:TIAAContractNumber>330292F5</ns4:TIAAContractNumber>
<ns4:CREFContractNumber>430292F3</ns4:CREFContractNumber>
<ns4:ContractName>GRA</ns4:ContractName>
</ns4:Source>
<ns4:Source>
...
</ns4:Source>
</ns4:Sources>
</ns4:VestingInfo>
Above xml is partial as completely it a big one so removed unrelated tags.
The resulting elements should be as below
ReslutingColumns
Found the solution. Below works perfectly for query like above
SELECT prty_rqst_id, vstng_src_on_sngl_sch, OMNI_PLN_NBR, sources.*
FROM cth01.rqst_payload pl,
XMLTABLE(xmlnamespaces (<namespaces>),
'//pathToXMLTagToBeExtracted/.../'
passing xmltype(pl.rqst_info)
COLUMNS
OMNI_PLN_NBR VARCHAR2(6) path 'ns4:Number'),
XMLTABLE(xmlnamespaces (<namespaces>),
'//pathToXMLTagToBeExtracted/...//ns4:VestingInfo'
passing xmltype(pl.rqst_info)
COLUMNS
vstng_src_on_sngl_sch VARCHAR2(50) path 'ns4:VestingSourcesOnSingleSchedule'),
XMLTABLE(xmlnamespaces (<namespaces>) ,
'//pathToXMLTagToBeExtracted/...//ns4:VestingInfo/ns4:Sources/ns4:Source'
passing xmltype(pl.rqst_info)
COLUMNS
src_id VARCHAR2(20) path 'ns4:SourceID',
src_nm VARCHAR2(50) path 'ns4:SourceName',
SUB_PLN_NBR VARCHAR2(16) path 'ns4:SubplanNumber',
vstd_pct NUMBER(20, 2) path 'ns4:VestedPercentage',
vstd_amt NUMBER(20, 2) path 'ns4:VestedAmount',
UPD_UNADJ_VSTD_PCT NUMBER(15,2) path 'ns4:UpdatedUnAdjustedVestedPercent',
unadj_vstd_pct NUMBER(20, 2) path 'ns4:UnAdjustedVestedPercent',
tiaa_cntrct_nbr VARCHAR2(50) path 'ns4:TIAAContractNumber',
cref_cntrct_nbr VARCHAR2(50) path 'ns4:CREFContractNumber',
cntrct_nm VARCHAR2(50) path 'ns4:ContractName' ) sources
WHERE pl.prty_rqst_id = '123')
Help needed to extract the data below from XML messages. I have table which contains the xml message in clob data type. I am trying using below query but it is not returning any data . I need to extract all the values from xml message.
<iORDERS:iORDERS xmlns:iORDERS="urn:iORDERS-abcdonline-com:Integration:v1">
<ORDER_NOTIFY>
<MESSAGE_DATETIME>2017-06-13T12:20:51+10:00</MESSAGE_DATETIME>
<MESSAGE_SEQ>1</MESSAGE_SEQ>
<MESSAGE_TYPE>PLACED</MESSAGE_TYPE>
<ORDER_HEAD>
<ORDER_ID>1111</ORDER_ID>
<DROP_SHIP_ORDER_NO></DROP_SHIP_ORDER_NO>
<CUSTOMER_ORDER_NO>22222</CUSTOMER_ORDER_NO>
<DISPATCH_LOCATION>
<SKU>2323234</SKU>
<UPC>4549432533626</UPC>
<REQUESTED_QTY>1</REQUESTED_QTY>
<DISPATCH_ASSIGNMENT>7777</DISPATCH_ASSIGNMENT>
<PROVIDER_ID>100</PROVIDER_ID>
<PKG_TYPE>SAT</PKG_TYPE>
</DISPATCH_LOCATION>
</ORDER_HEAD>
</ORDER_NOTIFY>
</iORDERS:iORDERS>
query :
select wor.batch_no,wor.web_service_no,x.*
from web_orders wo
cross join XMLTABLE (
XMLNAMESPACES(DEFAULT 'urn:iORDERS-abcdonline-com:Integration:v1'),
'iORDERS/ORDER_NOTIFY/ORDER_HEAD/DISPATCH_LOCATION'
passing xmltype(wo.xml_message)
columns
MESSAGE_TYPE varchar(120) path './../../../MESSAGE_TYPE') x;
You need to provide the named namespace identifier rather than a defealt, and your column path is going up one too many levels:
select wo.batch_no,wo.web_service_no,x.*
from web_orders wo
cross join XMLTABLE (
XMLNAMESPACES('urn:iORDERS-abcdonline-com:Integration:v1' as "iORDERS"),
'iORDERS:iORDERS/ORDER_NOTIFY/ORDER_HEAD/DISPATCH_LOCATION'
passing xmltype(wo.xml_message)
columns
MESSAGE_TYPE varchar(120) path './../../MESSAGE_TYPE') x;
BATCH_NO WEB_SERVICE_NO MESSAGE_TYPE
---------- -------------- ------------------------------------------------------------------------------------------------------------------------
1 2 PLACED
Presumably you're planning on getting for information that that from the XML, and/or expect to have multiple nodes; otherwise, to just get the message type you could simplify to:
select wo.batch_no,wo.web_service_no,x.*
from web_orders wo
cross join XMLTABLE (
XMLNAMESPACES('urn:iORDERS-abcdonline-com:Integration:v1' as "iORDERS"),
'iORDERS:iORDERS/ORDER_NOTIFY'
passing xmltype(wo.xml_message)
columns
MESSAGE_TYPE varchar(120) path 'MESSAGE_TYPE') x;
or even, with a single node:
select wo.batch_no,wo.web_service_no,XMLQuery(
'declare namespace iORDERS="urn:iORDERS-abcdonline-com:Integration:v1"; (: :)
iORDERS:iORDERS/ORDER_NOTIFY/MESSAGE_TYPE/text()'
passing xmltype(wo.xml_message)
returning content).getStringVal() as message_type
from web_orders wo;