I have an xml that looks like below
<ibm:dept bldg="123" xmlns:ibm="http://www.ibm.com/xmltable">
<ibm:employee id="144">
<ibm:name>
<ibm:first>James</ibm:first>
<ibm:last>Bond</ibm:last>
</ibm:name>
<ibm:office>007</ibm:office>
<ibm:phone>905-007-1007</ibm:phone>
<ibm:salary currency="USD">77007</ibm:salary>
</ibm:employee>
</ibm:dept>'
I am trying to parse it using XMLTable function. This is what I have tried -
select x.*,
y.*
from xml_tab t,
XMLTable(XMLnamespaces('http://www.ibm.com/xmltable' as "ibm"),
'ibm:dept/ibm:employee'
passing t.xml_data
columns
empid NUMBER path '@id',
office VARCHAR2(5) path 'ibm:office',
name XMLTYPE path 'ibm:name'
) x,
XMLTable(
'ibm:name'
passing x.name
columns
firstname VARCHAR2(10) path 'ibm:first',
lastname VARCHAR2(10) path 'ibm:last') y
where t.id =3;
However it's errored out with below error
ORA-19228: XPST0008 - undeclared identifier: prefix 'ibm' local-name 'ibm:name'
Hoping someone could explain the error. cheers!
Data Set up
create table xml_tab
(
id NUMBER,
xml_data XMLType
);
insert into xml_tab
values(3, XMLType.createXML('<ibm:dept bldg="123" xmlns:ibm="http://www.ibm.com/xmltable">
<ibm:employee id="144">
<ibm:name>
<ibm:first>James</ibm:first>
<ibm:last>Bond</ibm:last>
</ibm:name>
<ibm:office>007</ibm:office>
<ibm:phone>905-007-1007</ibm:phone>
<ibm:salary currency="USD">77007</ibm:salary>
</ibm:employee>
</ibm:dept>'));