ORA-19279
I have written the following SQL to get all the child names:
WITH xml_table AS
(SELECT xmltype('
<root>
<child name="name1">
<grandchild name="name11">
<greatgrandchild name="name111"/>
<greatgrandchild name="name112"/>
</grandchild>
<grandchild name="name12"/>
</child>
<child name="name2">
<grandchild name="name21"/>
<grandchild name="name22"/>
</child>
</root>') object_value FROM dual)
select po.*
from xml_table p,
xmltable('/root' passing p.object_value columns child varchar2(100) path 'child/@name') po;
I understand there are multiple "child" nodes under "root". So how to list them?
I want to store all the "child" names in one table, "child" nodes and their "grandchild" in another table, "grandchild" and "greatgrandchild" in another table. What should be SQLs?
Here's how you can "flatten" the hierarchy, it should give you some pointers to achieve your requirement :
WITH xml_table AS (
SELECT xmltype(
'<root>
<child name="name1">
<grandchild name="name11">
<greatgrandchild name="name111"/>
<greatgrandchild name="name112"/>
</grandchild>
<grandchild name="name12"/>
</child>
<child name="name2">
<grandchild name="name21"/>
<grandchild name="name22"/>
</child>
</root>'
) object_value
FROM dual
SELECT po1.child,
po2.grandchild,
po3.greatgrandchild
FROM xml_table p,
XMLTable(
'/root/child'
passing p.object_value
columns
child varchar2(100) path '@name',
childs xmltype path '.'
) po1,
XMLTable(
'/child/grandchild'
passing po1.childs
columns
grandchild varchar2(100) path '@name',
grandchilds xmltype path '.'
) (+) po2,
XMLTable(
'/grandchild/greatgrandchild'
passing po2.grandchilds
columns
greatgrandchild varchar2(100) path '@name'
) (+) po3
;To deal with missing descendants, note the use of the outer join with the last two XMLTABLEs.
Similar Messages
-
Hello,
How can I improve the XQuery below in order to obtain a minimised return to escape from both errors ORA-19279 and ORA-01706?
XQUERY for $book in fn:collection("oradb:/HR/TB_XML")//article let $cont := $book/bdy where $cont [ora:contains(text(), "(near((The,power,Love),10, TRUE))") > 0] return $book
ERROR:
ORA-19279: XPTY0004 - XQuery dynamic type mismatch: expected singleton sequence
- got multi-item sequence
XQUERY for $book in fn:collection("oradb:/HR/TB_XML")//article let $cont := $book/bdy where $cont [ora:contains(., "(near((The,power,Love),10, TRUE))") > 0] return $book//bdy
/*ERROR:
ORA-01706: user function result value was too large
Regards,
Daianebelow query works for 1 iteration . but for multiple sets i am getting following error .
When you want to present repeating groups in relational format, you have to extract the sequence of items in the main XQuery expression.
Each item is then passed to the COLUMNS clause to be further shredded into columns.
This should work as expected :
select x.*
from abc t
, xmltable(
xmlnamespaces(
default 'urn:swift:xsd:fin.970.2011'
, 'urn:swift:xsd:mtmsg.2011' as "ns0"
, '/ns0:FinMessage/ns0:Block4/Document/MT970/F61a/F61'
passing t.col1
columns F61ValueDate Varchar(40) Path 'ValueDate'
, DebitCreditMark Varchar(40) Path 'DebitCreditMark'
, Amount Varchar(40) Path 'Amount'
, TransactionType Varchar(40) Path 'TransactionType'
, IdentificationCode Varchar(40) Path 'IdentificationCode'
, ReferenceForTheAccountOwner Varchar(40) Path 'ReferenceForTheAccountOwner'
, SupplementaryDetails Varchar(40) Path 'SupplementaryDetails'
) x ; -
ORA-19279 error extracting one-to-many sequence
I have an xml table built from a registered schema that I'm trying to extract data from using a view. The lowest level is a polygon with multiple vertices -- vertices number, latitude, and longitude. The xml file lists data as
POLYGON
SEQ_NUM
LAT
LON
SEQ_NUM
LAT
LON
SEQ_NUM
LAT
LON
/POLYGON
The method I use to extract the data returns an ORA-19279 error: "XQuery dymanic type mismatch: expected singleton sequence - got multi-item sequence." The error is pointing to the polygon data; however the polygon sequence tag in the xsd file has the attribute of maxOccurs="unbounded".
Below is the xsd file, a samlpe xml file and the Select statement I use.
ABC.xsd file:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="A_B_C">
<xs:complexType>
<xs:sequence>
<xs:element name="A">
<xs:complexType>
<xs:sequence>
<xs:element name="B">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="1A"/>
<xs:enumeration value="1B"/>
<xs:enumeration value="2A"/>
<xs:enumeration value="2B"/>
<xs:enumeration value="2C"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:choice>
<xs:element name="D" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="D_ID" type="xs:string">
</xs:element>
<xs:element name="D_UQ_ID" type="xs:string">
</xs:element>
<xs:element name="D_TIME">
<xs:simpleType>
<xs:restriction base="xs:string"/>
</xs:simpleType>
</xs:element>
<xs:choice>
<xs:element name="F">
<xs:complexType>
<xs:sequence>
<xs:element name="F_TYPE" type="xs:string">
</xs:element>
<xs:element name="F_SUBTYPE" type="xs:string">
</xs:element>
<xs:element name="G" minOccurs="0">
<xs:complexType>
<xs:choice>
<xs:element name="H">
<xs:complexType>
<xs:sequence>
<xs:element name="H_TYPE" type="xs:string" minOccurs="0">
</xs:element>
<xs:element name="H_MODE" type="xs:string" minOccurs="0">
</xs:element>
<xs:element name="H_SHAPE" minOccurs="0">
<xs:complexType>
<xs:choice>
<xs:element name="POLYGON">
<xs:complexType>
{color:#ff0000}*<xs:sequence maxOccurs="unbounded">*{color}
<xs:element name="SEQ_NUM" type="xs:unsignedInt">
<xs:annotation>
<xs:documentation>sequence number in the polygon</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="LAT" type="xs:float"/>
<xs:element name="LON" type="xs:float"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="CIRCLE">
<xs:complexType>
<xs:sequence>
<xs:element name="LAT" type="xs:float"/>
<xs:element name="LON" type="xs:float"/>
<xs:element name="RAD" type="xs:float"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ELLIPSE">
<xs:complexType>
<xs:sequence>
<xs:element name="ORIENT">
<xs:simpleType>
<xs:restriction base="xs:float">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="360"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="MAJ_AX" type="xs:float">
</xs:element>
<xs:element name="MIN_AX" type="xs:float">
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="E">
<xs:complexType/>
</xs:element>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="C">
</xs:element>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
abc.xml file:
<?xml version="1.0" encoding="utf-8"?>
<A_B_C>
<A>
<B>1B</B>
</A>
<D>
<D_ID>D_0001</D_ID>
<D_UQ_ID>UQ_D_0001</D_UQ_ID>
<D_TIME>2007 FEB 11:11:11.11</D_TIME>
<F>
<F_TYPE>F_TYPE_TEST</F_TYPE>
<F_SUBTYPE>SUB_TEST</F_SUBTYPE>
<G>
<H>
<H_TYPE>Ipod</H_TYPE>
<H_MODE>SCANNING</H_MODE>
<H_SHAPE>
<POLYGON>
<SEQ_NUM>1</SEQ_NUM>
<LAT>10.1</LAT>
<LON>11.1</LON>
<SEQ_NUM>2</SEQ_NUM>
<LAT>20.2</LAT>
<LON>22.2</LON>
<SEQ_NUM>3</SEQ_NUM>
<LAT>30.3</LAT>
<LON>33.3</LON>
<SEQ_NUM>4</SEQ_NUM>
<LAT>40.4</LAT>
<LON>44.4</LON>
</POLYGON>
<CIRCLE>
<LAT>12.3</LAT>
<LON>45.6</LON>
<RAD>78.9</RAD>
</CIRCLE>
<ELLIPSE>
<ORIENT>99.90</ORIENT>
<MAJ_AX>111.10</MAJ_AX>
<MIN_AX>222.20</MIN_AX>
</ELLIPSE>
</H_SHAPE>
</H>
</G>
</F>
<E></E>
</D>
<D>
<D_ID>D_0002</D_ID>
<D_UQ_ID>UQ_D_0002</D_UQ_ID>
<D_TIME>2007 FEB 22:22:22.22</D_TIME>
<F>
<F_TYPE>F_TYPE_TEST</F_TYPE>
<F_SUBTYPE>SUB_TEST</F_SUBTYPE>
<G>
<H>
<H_TYPE>Ipod</H_TYPE>
<H_MODE>SCANNING</H_MODE>
<H_SHAPE>
<POLYGON>
<SEQ_NUM>1</SEQ_NUM>
<LAT>10.1</LAT>
<LON>11.1</LON>
<SEQ_NUM>2</SEQ_NUM>
<LAT>20.2</LAT>
<LON>22.2</LON>
<SEQ_NUM>3</SEQ_NUM>
<LAT>30.3</LAT>
<LON>33.3</LON>
<SEQ_NUM>4</SEQ_NUM>
<LAT>40.4</LAT>
<LON>44.4</LON>
</POLYGON>
<CIRCLE>
<LAT>12.3</LAT>
<LON>45.6</LON>
<RAD>78.9</RAD>
</CIRCLE>
<ELLIPSE>
<ORIENT>99.90</ORIENT>
<MAJ_AX>111.10</MAJ_AX>
<MIN_AX>222.20</MIN_AX>
</ELLIPSE>
</H_SHAPE>
</H>
</G>
</F>
<E></E>
</D>
<D>
<D_ID>D_0003</D_ID>
<D_UQ_ID>UQ_D_0003</D_UQ_ID>
<D_TIME>2007 FEB 33:33:33.33</D_TIME>
<F>
<F_TYPE>F_TYPE_TEST</F_TYPE>
<F_SUBTYPE>SUB_TEST</F_SUBTYPE>
<G>
<H>
<H_TYPE>Ipod</H_TYPE>
<H_MODE>SCANNING</H_MODE>
</H>
</G>
</F>
<E></E>
</D>
<D>
<D_ID>D_0004</D_ID>
<D_UQ_ID>UQ_D_0004</D_UQ_ID>
<D_TIME>2007 FEB 44:44:44.44</D_TIME>
<F>
<F_TYPE>F_TYPE_TEST</F_TYPE>
<F_SUBTYPE>SUB_TEST</F_SUBTYPE>
<G>
<H>
<H_TYPE>Ipod</H_TYPE>
<H_MODE>SCANNING</H_MODE>
<H_SHAPE>
<POLYGON>
<SEQ_NUM>1</SEQ_NUM>
<LAT>10.1</LAT>
<LON>11.1</LON>
<SEQ_NUM>2</SEQ_NUM>
<LAT>20.2</LAT>
<LON>22.2</LON>
<SEQ_NUM>3</SEQ_NUM>
<LAT>30.3</LAT>
<LON>33.3</LON>
<SEQ_NUM>4</SEQ_NUM>
<LAT>40.4</LAT>
<LON>44.4</LON>
</POLYGON>
<CIRCLE>
<LAT>12.3</LAT>
<LON>45.6</LON>
<RAD>78.9</RAD>
</CIRCLE>
<ELLIPSE>
<ORIENT>99.90</ORIENT>
<MAJ_AX>111.10</MAJ_AX>
<MIN_AX>222.20</MIN_AX>
</ELLIPSE>
</H_SHAPE>
</H>
</G>
</F>
<E></E>
</D>
<D>
<D_ID>D_0005</D_ID>
<D_UQ_ID>UQ_D_0005</D_UQ_ID>
<D_TIME>2007 FEB 55:55:55.55</D_TIME>
<F>
<F_TYPE>F_TYPE_TEST</F_TYPE>
<F_SUBTYPE>SUB_TEST</F_SUBTYPE>
</F>
<E></E>
</D>
<D>
<D_ID>D_0006</D_ID>
<D_UQ_ID>UQ_D_0006</D_UQ_ID>
<D_TIME>2007 FEB 66:66:66.66</D_TIME>
<F>
<F_TYPE>F_TYPE_TEST</F_TYPE>
<F_SUBTYPE>SUB_TEST</F_SUBTYPE>
<G>
<H>
<H_TYPE>Ipod</H_TYPE>
<H_MODE>SCANNING</H_MODE>
<H_SHAPE>
<POLYGON>
<SEQ_NUM>1</SEQ_NUM>
<LAT>10.1</LAT>
<LON>11.1</LON>
<SEQ_NUM>2</SEQ_NUM>
<LAT>20.2</LAT>
<LON>22.2</LON>
<SEQ_NUM>3</SEQ_NUM>
<LAT>30.3</LAT>
<LON>33.3</LON>
<SEQ_NUM>4</SEQ_NUM>
<LAT>40.4</LAT>
<LON>44.4</LON>
</POLYGON>
<CIRCLE>
<LAT>12.3</LAT>
<LON>45.6</LON>
<RAD>78.9</RAD>
</CIRCLE>
<ELLIPSE>
<ORIENT>99.90</ORIENT>
<MAJ_AX>111.10</MAJ_AX>
<MIN_AX>222.20</MIN_AX>
</ELLIPSE>
</H_SHAPE>
</H>
</G>
</F>
<E></E>
</D>
<D>
<D_ID>D_0007</D_ID>
<D_UQ_ID>UQ_D_0007</D_UQ_ID>
<D_TIME>2007 FEB 77:77:77.77</D_TIME>
<F>
<F_TYPE>F_TYPE_TEST</F_TYPE>
<F_SUBTYPE>SUB_TEST</F_SUBTYPE>
<G>
<H>
<H_TYPE>Ipod</H_TYPE>
<H_MODE>SCANNING</H_MODE>
</H>
</G>
</F>
<E></E>
</D>
<D>
<D_ID>D_0008</D_ID>
<D_UQ_ID>UQ_D_0008</D_UQ_ID>
<D_TIME>2007 FEB 88:88:88.88</D_TIME>
<F>
<F_TYPE>F_TYPE_TEST</F_TYPE>
<F_SUBTYPE>SUB_TEST</F_SUBTYPE>
<G>
<H>
<H_TYPE>Ipod</H_TYPE>
<H_MODE>SCANNING</H_MODE>
<H_SHAPE>
<POLYGON>
<SEQ_NUM>1</SEQ_NUM>
<LAT>10.1</LAT>
<LON>11.1</LON>
<SEQ_NUM>2</SEQ_NUM>
<LAT>20.2</LAT>
<LON>22.2</LON>
<SEQ_NUM>3</SEQ_NUM>
<LAT>30.3</LAT>
<LON>33.3</LON>
<SEQ_NUM>4</SEQ_NUM>
<LAT>40.4</LAT>
<LON>44.4</LON>
</POLYGON>
<CIRCLE>
<LAT>12.3</LAT>
<LON>45.6</LON>
<RAD>78.9</RAD>
</CIRCLE>
<ELLIPSE>
<ORIENT>88.80</ORIENT>
<MAJ_AX>111.10</MAJ_AX>
<MIN_AX>222.20</MIN_AX>
</ELLIPSE>
</H_SHAPE>
</H>
</G>
</F>
<E></E>
</D>
<C>TPS Report 4</C>
</A_B_C>
SELECT statement:
SELECT a_level.a_class
, d_level.D_UQ_ID
, d_level.D_TIME
, h_level.SEQ_NUM
, h_level.LAT
, h_level.LON
FROM ABC_XML,
XMLTABLE('/A_B_C'
PASSING ABC_XML.ABC_SPEC
COLUMNS
A_CLASS VARCHAR2(4000 BYTE) PATH '/A_B_C/A/B'
, D XMLTYPE PATH 'D'
) a_level,
XMLTABLE ('/D'
PASSING a_level.D
COLUMNS
D_UQ_ID varchar2(4000) PATH 'D_UQ_ID'
, D_TIME varchar2(4000) PATH 'D_TIME'
, POLYGON XMLTYPE PATH 'F/G/H/H_SHAPE/POLYGON'
) d_level
XMLTABLE('/POLYGON'
passing d_level.POLYGON
COLUMNS
SEQ_NUM NUMBER PATH 'SEQ_NUM'
, LAT NUMBER PATH 'LAT)'
, LON NUMBER PATH 'LON'
) h_level;
As you see I need to return data from three levels of data (a, d and h). I can remark out the bottom level (h_level) and the statement runs returning 8 rows from the xml file above (which is correct). The h_level XMLTABLE reference returns the ORA-19279 error. The full statement should return 20 rows of data.Yes. I looked at that string.
Never mind on this one. You helped solve the problem in another string
XMLTable 'For $i in ... return ROW' clause help needed -
Hi ,
I executed the below query in database version 11.2.0.3.0, it throws the error like "ORA-19279: XPTY0004 - XQuery dynamic type mismatch: expected singleton sequence - got multi-item sequence"
with PAYMENT_XML as (
select XMLTYPE(
'<Document>
<pain.002.001.02>
<GrpHdr>
<MsgId>CITIBANK/20091204-PSR/4274</MsgId>
<CreDtTm>2009-12-04T09:36:00</CreDtTm>
</GrpHdr>
<OrgnlGrpInfAndSts>
<OrgnlMsgId>10002</OrgnlMsgId>
<OrgnlMsgNmId>pain.001.001.02</OrgnlMsgNmId>
<OrgnlNbOfTxs>20</OrgnlNbOfTxs>
<OrgnlCtrlSum>7000</OrgnlCtrlSum>
<GrpSts>PART</GrpSts>
<StsRsnInf>
<AddtlStsRsnInf>ACK - FILE PARTIALLY SUCCESSFUL</AddtlStsRsnInf>
</StsRsnInf>
</OrgnlGrpInfAndSts>
<OrgnlGrpInfAndSts>
<OrgnlMsgId>10001</OrgnlMsgId>
<OrgnlMsgNmId>pain.001.001.02</OrgnlMsgNmId>
<OrgnlNbOfTxs>202</OrgnlNbOfTxs>
<OrgnlCtrlSum>9000</OrgnlCtrlSum>
<GrpSts>PART</GrpSts>
<StsRsnInf>
<AddtlStsRsnInf>ACK - FILE PARTIALLY SUCCESSFUL</AddtlStsRsnInf>
<AddtlStsRsnInf>Formated</AddtlStsRsnInf>
</StsRsnInf>
</OrgnlGrpInfAndSts>
</pain.002.001.02>
</Document>') as OBJECT_VALUE1
from dual
select R.*
from PAYMENT_XML,
XMLTABLE(
'for $COMP in $COMPANY/Document/pain.002.001.02
for $DEPT at $DEPTIDX in $COMP/OrgnlGrpInfAndSts
return <RESULT>
<NAME>{fn:data($COMP/GrpHdr/MsgId)}</NAME>
$DEPT/OrgnlMsgId,
$DEPT/OrgnlNbOfTxs,
$DEPT/OrgnlCtrlSum,
$DEPT/GrpSts,
$DEPT/StsRsnInf/AddtlStsRsnInf
</RESULT>'
passing OBJECT_VALUE1 as "COMPANY"
columns
NAME VARCHAR(10) path 'NAME',
OrgnlMsgId VARCHAR2(24) path 'OrgnlMsgId',
ORGNLNBOFTXS VARCHAR2(24) path 'OrgnlNbOfTxs',
ORGNLCTRLSUM NUMBER path 'OrgnlCtrlSum',
GRPSTS VARCHAR2(24) path 'GrpSts',
ADDTLSTSRSNINF VARCHAR2(40) path 'AddtlStsRsnInf'
) r
Errors comes this part :
<StsRsnInf>
<AddtlStsRsnInf>ACK - FILE PARTIALLY SUCCESSFUL</AddtlStsRsnInf>
<AddtlStsRsnInf>Formated</AddtlStsRsnInf>
</StsRsnInf>
if i put the single statement for this xml element <AddtlStsRsnInf> it works fine if more than one element comes it raised the error.
i want the output like the below format : want to merge the element value with (, comma) delimiter with single coloumn value
NAME
ORGNLMSGID
ORGNLNBOFTXS
ORGNLCTRLSUM
GRPSTS
ADDTLSTSRSNINF
CITIBANK/2
10002
20
7,000
PART
ACK - FILE PARTIALLY SUCCESSFUL
CITIBANK/2
10001
202
9,000
PART
ACK - FILE PARTIALLY SUCCESSFUL, Formated
Thanks is advance for reply
Thanks,
ChidamTry with XQuery string-join() function :
ADDTLSTSRSNINF VARCHAR2(40) path 'string-join(AddtlStsRsnInf, ", ")' -
ORA-19279: XPTY0004 - XQuery dynamic type mismatch: expected singleton sequ
I have been working with XML files containing only one record. I downloaded instructions to create/insert/select and the statements below work fine for the XML files with one record. Now I have XML files with multiple records/sections, but the select statement returns ORA-19279. How would I change the create/insert/select statements to handle XML files with more than one record? There is still only one vendata section, but there are multiple VendorData sections.
Thanks.
1. Create a table with an XML column:
create table vendxml_col (
vend_id number primary key,
vend_doc XMLType);
2. Insert xml document:
insert into vendxml_col values (1,
XMLType(bfilename('ING_FEED', 'VenData.xml'),
nls_charset_id('AL32UTF8')));
3. Query the xml columns in vendxml_col:
select vend_id,
a.cage, a.repl_cage, a.status, a.company1, a.company2, a.address1, a.address2,
a.pobox, a.city, a.state, a.zip, a.country, a.phone, a.fax, a.cao, a.adpp,
a.assoc, a.type, a.affil, a.sizex, a.pri_bus, a.type_bus, a.woman, a.sic,
a.formerly, a.formerly2, a.comp1key, a.comp2key, a.Revseq, a.Source,
a.RequestID
FROM vendxml_col,
XMLTABLE('/vendata'
PASSING vendxml_col.vend_doc
COLUMNS
cage varchar2(5) PATH '/vendata/VendorData/cage',
repl_cage varchar2(5) PATH '/vendata/VendorData/repl_cage',
status varchar2(1) PATH '/vendata/VendorData/status',
company1 varchar2(30) PATH '/vendata/VendorData/company1',
company2 varchar2(30) PATH '/vendata/VendorData/company2',
address1 varchar2(40) PATH '/vendata/VendorData/address1',
address2 varchar2(40) PATH '/vendata/VendorData/address2',
pobox varchar2(10) PATH '/vendata/VendorData/pobox',
city varchar2(30) PATH '/vendata/VendorData/city',
state varchar2(2) PATH '/vendata/VendorData/state',
zip varchar2(20) PATH '/vendata/VendorData/zip',
country varchar2(20) PATH '/vendata/VendorData/country',
phone varchar2(20) PATH '/vendata/VendorData/phone',
fax varchar2(20) PATH '/vendata/VendorData/fax',
cao varchar2(20) PATH '/vendata/VendorData/cao',
adpp varchar2(20) PATH '/vendata/VendorData/adpp',
assoc varchar2(20) PATH '/vendata/VendorData/assoc',
type varchar2(1) PATH '/vendata/VendorData/type',
affil varchar2(1) PATH '/vendata/VendorData/affil',
sizex varchar2(1) PATH '/vendata/VendorData/sizex',
pri_bus varchar2(1) PATH '/vendata/VendorData/pri_bus',
type_bus varchar2(1) PATH '/vendata/VendorData/type_bus',
woman varchar2(1) PATH '/vendata/VendorData/woman',
sic varchar2(4) PATH '/vendata/VendorData/sic',
formerly varchar2(5) PATH '/vendata/VendorData/formerly',
formerly2 varchar2(5) PATH '/vendata/VendorData/formerly2',
comp1key varchar2(30) PATH '/vendata/VendorData/comp1key',
comp2key varchar2(30) PATH '/vendata/VendorData/comp2key',
Revseq varchar2(1) PATH '/vendata/VendorData/Revseq',
Source varchar2(3) PATH '/vendata/VendorData/Source',
RequestID varchar2(3) PATH '/vendata/VendorData/RequestID'
) a
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Jun 9 13:28:00 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>select * from V$VERSION;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
Edited by: user8058903 on Jun 9, 2011 11:28 AMWelcome to the XML DB forums.
As everything in your sample XML is coming from the VendorData node, you can just include that in the XQuery string parm such as shown below. As you didn't include any sample XML, I just built a really simple test case with two VendorData nodes. As the note says, I used WITH to simulate your table/data because I was too lazy to create and populate a table in my playground.
WITH vendxml_col AS
(SELECT 1 vend_id,
XMLTYPE('<vendata><VendorData><cage>c1</cage></VendorData>
<VendorData><cage>c2</cage></VendorData></vendata>') vend_doc
FROM dual)
-- Above WITH used to simulate your table/data. You only care about below
SELECT vend_id, a.cage
FROM vendxml_col,
XMLTABLE('/vendata/VendorData'
PASSING vendxml_col.vend_doc
COLUMNS
cage VARCHAR2(5) PATH 'cage') a;
VEND_ID CAGE
1 c1
1 c2 -
How to overcome ORA-19279 error
Hi,
I have oracle 11.2.2 and following xml is loaded in xmltype table and trying to retrive data and getting following error, please anyone could help me to fix this error
<?xml version="1.0" encoding="utf-8"?>
<agents count="1382">
<agent>
<name>Nancy Palmer</name>
<email>[email protected]</email>
<agentid>MLSL:00525350</agentid>
<officeid>58</officeid>
<website>http://www.nancypalmer.com</website>
<photo>https://sites.e-agents.com/Uploads/68/41/6841/Agents/agent_8418_NANCY_PALMER_COLOR_HEAD_SHOT_HIGH_QUALITY_2011.jpg</photo>
<phone_direct>6504344313</phone_direct>
<phone_cell>6504920200</phone_cell>
<mod_time>2012-08-31T05:15:06.933</mod_time>
</agent>
<agent>
<name>Genella Williamson</name>
<email>[email protected]</email>
<agentid>MLSL:00755754</agentid>
<officeid>58</officeid>
<website>http://www.apr.com/genella</website>
<photo>https://sites.e-agents.com/Uploads/68/41/6841/Agents/agent_8426_genella.jpg</photo>
<phone_direct>6504344319</phone_direct>
<phone_cell>6507870839</phone_cell>
<mod_time>2010-10-30T15:15:07.603</mod_time>
</agent>
<agent>
<name>Diana Langley</name>
<email>[email protected]</email>
<agentid>MLSL:01256202,SFAR:805608</agentid>
<officeid>50</officeid>
<website>http://www.apr.com/DLangley</website>
<photo>https://sites.e-agents.com/Uploads/68/41/6841/Agents/agent_7848_dlangley.jpg</photo>
<phone_direct/>
<phone_cell/>
<mod_time>2011-06-06T05:15:06.587</mod_time>
</agent>
</agents>
query usered to reterive data
SELECT count, NAME, email,
officeid, website,
photo, phone_direct,
phone_cell, mod_date
FROM TEMP_XML tx,
XMLTable('/agents'
PASSING tx.xml_data
columns count varchar2(30) path '@count',
NAME VARCHAR2(100) path 'agent/name',
email VARCHAR2(100) path 'agent/email',
officeid VARCHAR2(100) path 'agent/officeid',
website VARCHAR2(100) path 'agent/website',
photo VARCHAR2(100) path 'agent/photo',
phone_direct VARCHAR2(100) path 'agent/phone_direct',
phone_cell VARCHAR2(100) path 'agent/phone_cell',
mod_date VARCHAR2(100) path 'agent/mod_date'
recieved error
ORA-19279: XPTY0004 - XQuery dynamic type mismatch: expected singleton sequence - got multi-item sequence
19279. 00000 - "XQuery dynamic type mismatch: expected singleton sequence - got multi-item sequence"
*Cause: The XQuery sequence passed in had more than one item.
*Action: Correct the XQuery expression to return a single item sequence.Thanks in advance
Best Regards,use
SELECT count,
NAME,
email,
officeid,
website,
photo,
phone_direct,
phone_cell,
mod_date
FROM TEMP_XML tx,
XMLTable('agents' PASSING tx.xml_data
columns count varchar2(30) path '@count',
xml_part xmltype path '*') x,
XMLTable('agent' PASSING x.xml_part
columns NAME VARCHAR2(100) path 'name',
email VARCHAR2(100) path 'email',
officeid VARCHAR2(100) path 'officeid',
website VARCHAR2(100) path 'website',
photo VARCHAR2(100) path 'photo',
phone_direct VARCHAR2(100) path 'phone_direct',
phone_cell VARCHAR2(100) path 'phone_cell',
mod_date VARCHAR2(100) path 'mod_date') y -
ORA-19279: Query dynamic type mismatch: expected singleton sequence
Hi,
I have my xml stored in the table 'xml_table’
The content of XML is a follows:
<COMPANY NAME="ABC">
<DEPARTMENT_NAME>Paris</DEPARTMENT_NAME>
<ADDRESS>Rue de nevers</ADDRESS>
<DEPARTMENT_NAME>London</DEPARTMENT_NAME>
<ADDRESS>Northampton Square</ADDRESS>
</COMPANY>
I would like to query the xml to get the output like that:
COMPANY_NAME | DEPARTMENT_NAME | ADDRESS
ABC | Paris | rue de nevers
ABC | London | Northampton Square
However when I execute the query:
SELECT t.company_name, t.address, t.department_name
FROM xml_table p,
XMLTable('/COMPANY' PASSING p.OBJECT_VALUE
COLUMNS company_name PATH '@NAME',
address VARCHAR2(100) PATH '/COMPANY/ADDRESS',
department_name VARCHAR2(100) PATH '/COMPANY/DEPARTMENT_NAME') t
I am getting error:
ORA-19279: XPTY0004 - XQuery dynamic type mismatch: expected singleton sequence - got multi-item sequence
What can be wrong with the query? Howe should it be modified to get desired output?
Thank for help
GroxyAs was mentioned... Enclosing the tags for each department in a DEPARTMENT tag would make this easier and more effiecient but here's an alternative approach if modifying the XML is not an option
SQL> with COMPANY_XML as
2 (
3 select XMLTYPE(
4 '<COMPANY NAME="ABC">
5 <DEPARTMENT_NAME>Paris</DEPARTMENT_NAME>
6 <ADDRESS>Rue de nevers</ADDRESS>
7 <DEPARTMENT_NAME>London</DEPARTMENT_NAME>
8 <ADDRESS>Northampton Square</ADDRESS>
9 </COMPANY>') as OBJECT_VALUE from dual
10 )
11 select R.*
12 from COMPANY_XML,
13 XMLTABLE
14 (
15 'for $COMP in $COMPANY/COMPANY
16 for $DEPT at $DEPTIDX in $COMP/DEPARTMENT_NAME
17 return <RESULT>
18 <NAME>{fn:data($COMP/@NAME)}</NAME>
19 {
20 $COMP/DEPARTMENT_NAME[$DEPTIDX],
21 $COMP/ADDRESS[$DEPTIDX]
22 }
23 </RESULT>'
24 passing OBJECT_VALUE as "COMPANY"
25 ) r
26 /
COLUMN_VALUE
<RESULT><NAME>ABC</NAME><DEPARTMENT_NAME>Paris</DEPARTMENT_NAME><ADDRESS>Rue de
nevers</ADDRESS></RESULT>
<RESULT><NAME>ABC</NAME><DEPARTMENT_NAME>London</DEPARTMENT_NAME><ADDRESS>Northa
mpton Square</ADDRESS></RESULT>This above step creates a document for all tags with a particular index and then we can apply a columns cause to get the results..
SQL> with COMPANY_XML as
2 (
3 select XMLTYPE(
4 '<COMPANY NAME="ABC">
5 <DEPARTMENT_NAME>Paris</DEPARTMENT_NAME>
6 <ADDRESS>Rue de nevers</ADDRESS>
7 <DEPARTMENT_NAME>London</DEPARTMENT_NAME>
8 <ADDRESS>Northampton Square</ADDRESS>
9 </COMPANY>') as OBJECT_VALUE from dual
10 )
11 select R.*
12 from COMPANY_XML,
13 XMLTABLE
14 (
15 'for $COMP in $COMPANY/COMPANY
16 for $DEPT at $DEPTIDX in $COMP/DEPARTMENT_NAME
17 return <RESULT>
18 <NAME>{fn:data($COMP/@NAME)}</NAME>
19 {
20 $COMP/DEPARTMENT_NAME[$DEPTIDX],
21 $COMP/ADDRESS[$DEPTIDX]
22 }
23 </RESULT>'
24 passing OBJECT_VALUE as "COMPANY"
25 columns
26 NAME VARCHAR(10),
27 DEPARTMENT_NAME VARCHAR2(24),
28 ADDRESS VARCHAR2(24)
29 ) r
30 /
NAME DEPARTMENT_NAME ADDRESS
ABC Paris Rue de nevers
ABC London Northampton Square
SQL> -
I've got an xml file that I'm loading into a view defined as an xmlType. The view name is eachFile with a single column of myType that is defined as an xmlType. The structure of the xml is:
<CASE_BATCH>
<CASE_COUNT>2</CASE_COUNT>
<XML_BATCH_TRANS>1012</XML_BATCH_TRANS>
<XML_BATCH_DATE>02/07/2007 14:46:14</XML_BATCH_DATE>
<CASEDETAIL>
<HEADER>
<CASE_TRANS>1044</CASE_TRANS>
<UPDATE_TYPE>I</UPDATE_TYPE>
<CASE>26968</CASE>
<PERSON_ID>197192</PERSON_ID>
+<NAME>
</NAME>
+<ADDRESS>
</ADDRESS>
+<VITAL_STATS>
</VITAL_STATS>
+<MEDICAL>
</MEDICAL>
+<RESIDENCY>
</RESIDENCY>
+<DESCRIPTION>
</DESCRIPTION>
+<SCHOOL>
</SCHOOL>
<OTHER>
</OTHER>
</HEADER>
<CASEDETAIL>
<HEADER>
<CASE_TRANS>1045</CASE_TRANS>
<UPDATE_TYPE>I</UPDATE_TYPE>
<CASE>26969</CASE>
<PERSON_ID>197193</PERSON_ID>
</<CASE_BATCH>
I've omitted non-essential data, but in general the structure is that within each <CASE_BATCH> tag there is the potential of multiple <CASE_DETAIL> tags, and each <CASE_DETAIL> tag has some data of which the <PERSON_ID> is what I need to retrieve.
I've tried several different approaches to retrieve <PERSON_ID> tag value, but nothing I try works, I either get no rows returned or an ORA-19279. What I'd like to do is open this up in a stored procedure as a cursor so I can loop through the subordinate data in the xml format and do some insertion/modification of relational tables.
Here's what I've tried that seemed to me to be the most promising:
select a.*
from eachFile,
xmltable('/CASE_BATCH'
passing eachfile.mytype
columns
extnum varchar2(30) PATH '/CASE_BATCH/CASEDETAIL/HEADER/PERSON_ID') a
How query an xml-based view knowing that it may return multiple rows?I do need other columns at that level, but I've gotten that to work simply by adding additional column definitions at that level. I'm trying to do this process incrementally so I can tell when I break things. Now that I've gotten the first level of query to work, I need to do some queries against some of the lower levels. What I had in mind was to use the number retrieved as 'extnum' as a part of the where clause for additional queries. Unfortunately, now I can't get that level to work.
Here's what I've got now:
select B.*
from eachFile,
xmltable('/CASE_BATCH/CASEDETAIL'
passing eachfile.mytype
columns
extnum number PATH '/CASEDETAIL/HEADER/PERSON_ID') A,
xmltable('CASE_BATCH/CASEDETAIL'
passing eachfile.mytype
columns
extnum number PATH '/CASEDETAIL/HEADER/PERSON_ID',
firstName varchar2(30) PATH '/NAME/FIRSTNAME',
middleName varchar2(30) path '/NAME/MIDDLENAME',
lastName varchar2(30) path '/NAME/LASTNAME',
suffix varchar2(30) path '/NAME/SUFFIX') b
where
a.extnum = 214339 AND
a.extnum = b.extnum
This query as written returns the extnum value (The hard-coded value is one retrieved from the previous query that I'm just using to test with) but no name data. I have no doubt this is related to how you specitfy the path in both or either the xmlTable or the column definition, but I don't understand the correct way to specify it, especially when I'm using a comparative value that's at a higher node in the XML than the subordinate nodes data that I need to retrieve.
I've got a whole bunch of this type of query to write at lower and lower nodes in the XML structure, so once I get this one to work, I am (hopefully!) good to go. How can I use a higher node's value to query subordinate node data when there are multiples of the higher node? -
ORA-19279 How do I write a query to return the data?
I have XMLType tables in Oracle 11. I insert XML data from documents and each table only contains one XML document. I can write queries to return outer tags and inner tags but not outer and inner tags in the same result set. There can be one to many InvoiceLineRet tags to each InvoiceRet tag.
Any and all help is appreciated.
Mike
This works and returns RefNumber for the invoice at the InvoiceRet level.
SELECT
a.RefNumber
FROM InvoiceQueryRs xt,
XMLTable('//InvoiceRet' PASSING xt.OBJECT_VALUE COLUMNS
RefNumber VARCHAR2(255) PATH 'RefNumber') a;
This works and returns the two columns from the InvoiceLineRet level.
SELECT
b.ILR_ItemRef_FullName,
b.ILR_Desc
FROM InvoiceQueryRs xt,
XMLTable('//InvoiceLineRet' PASSING xt.OBJECT_VALUE COLUMNS
ILR_ItemRef_FullName VARCHAR2(255) PATH 'ItemRef/FullName',
ILR_Desc VARCHAR2(2000) PATH 'Desc') b
But a query like this does not work.
SELECT
b.RefNumber,
b.ILR_ItemRef_FullName,
b.ILR_Desc
FROM InvoiceQueryRs xt,
XMLTable('//InvoiceRet' PASSING xt.OBJECT_VALUE COLUMNS
RefNumber VARCHAR2(255) PATH 'RefNumber',
ILR_ItemRef_FullName VARCHAR2(255) PATH 'InvoiceLineRet/ItemRef/FullName',
ILR_Desc VARCHAR2(2000) PATH 'InvoiceLineRet/Desc') b
This query returns data but every row has the same RefNumber.
SELECT
a.RefNumber,
b.ILR_ItemRef_ListID,
b.ILR_ItemRef_FullName,
b.ILR_Desc
FROM InvoiceQueryRs xt,
XMLTable('//InvoiceRet' PASSING xt.OBJECT_VALUE COLUMNS
RefNumber VARCHAR2(255) PATH 'RefNumber') a,
XMLTable('//InvoiceLineRet' PASSING xt.OBJECT_VALUE COLUMNS
ILR_ItemRef_ListID VARCHAR2(255) PATH 'ItemRef/ListID',
ILR_ItemRef_FullName VARCHAR2(255) PATH 'ItemRef/FullName',
ILR_Desc VARCHAR2(2000) PATH 'Desc') b
Example of the XML:
<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid XML Studio 1.0.8.0 (http://www.liquid-technologies.com) -->
<TEST>
<InvoiceRet>
<TxnID>D924-1210085400</TxnID>
<TimeCreated>2008-05-06T10:50:00-05:00</TimeCreated>
<TimeModified>2008-07-21T10:54:42-05:00</TimeModified>
<EditSequence>1215638595</EditSequence>
<TxnNumber>10398</TxnNumber>
<CustomerRef>
<ListID>80000278-1209483158</ListID>
<FullName>Majestic Entries</FullName>
</CustomerRef>
<ARAccountRef>
<ListID>80000009-1185470478</ListID>
<FullName>Accounts Receivable</FullName>
</ARAccountRef>
<TemplateRef>
<ListID>80000019-1190228214</ListID>
<FullName>Compudoc</FullName>
</TemplateRef>
<TxnDate>2008-05-06</TxnDate>
<RefNumber>22333</RefNumber>
<BillAddress>
<Addr1>Majetic Entries</Addr1>
</BillAddress>
<BillAddressBlock>
<Addr1>Majetic Entries</Addr1>
</BillAddressBlock>
<IsPending>false</IsPending>
<IsFinanceCharge>false</IsFinanceCharge>
<DueDate>2008-05-06</DueDate>
<ShipDate>2008-05-06</ShipDate>
<Subtotal>391.50</Subtotal>
<ItemSalesTaxRef>
<ListID>8000004F-1185996977</ListID>
<FullName>NC 7.25%</FullName>
</ItemSalesTaxRef>
<SalesTaxPercentage>7.25</SalesTaxPercentage>
<SalesTaxTotal>5.73</SalesTaxTotal>
<AppliedAmount>-397.23</AppliedAmount>
<BalanceRemaining>0.00</BalanceRemaining>
<IsPaid>true</IsPaid>
<IsToBePrinted>false</IsToBePrinted>
<IsToBeEmailed>false</IsToBeEmailed>
<CustomerSalesTaxCodeRef>
<ListID>80000001-1185469345</ListID>
<FullName>Tax</FullName>
</CustomerSalesTaxCodeRef>
<InvoiceLineRet>
<TxnLineID>D926-1210085400</TxnLineID>
<ItemRef>
<ListID>80000059-1199714336</ListID>
<FullName>Labor:Non-Contract Labor Ken</FullName>
</ItemRef>
<Desc>Technical Labor performed by Ken Allen:
Network Problem with Internet and intranet found two routers connected together and the one set for DHCP was bad we changed out their bad one with our small netgear router.</Desc>
<Quantity>1.5</Quantity>
<Rate>125.00</Rate>
<ClassRef>
<ListID>8000000D-1200208143</ListID>
<FullName>KA</FullName>
</ClassRef>
<Amount>187.50</Amount>
<ServiceDate>2008-04-28</ServiceDate>
<SalesTaxCodeRef>
<ListID>80000002-1185469345</ListID>
<FullName>Non</FullName>
</SalesTaxCodeRef>
</InvoiceLineRet>
<InvoiceLineRet>
<TxnLineID>D927-1210085400</TxnLineID>
<ItemRef>
<ListID>80000029-1185470511</ListID>
<FullName>Labor:Non-Contract Labor Rick</FullName>
</ItemRef>
<Desc>Technical Labor performed by Rick Wagoner: Assisted with above troubleshooting</Desc>
<Quantity>1</Quantity>
<Rate>125.00</Rate>
<ClassRef>
<ListID>80000004-1185998300</ListID>
<FullName>RW</FullName>
</ClassRef>
<Amount>125.00</Amount>
<ServiceDate>2008-04-28</ServiceDate>
<SalesTaxCodeRef>
<ListID>80000002-1185469345</ListID>
<FullName>Non</FullName>
</SalesTaxCodeRef>
</InvoiceLineRet>
<InvoiceLineRet>
<TxnLineID>D928-1210085400</TxnLineID>
<ItemRef>
<ListID>80000050-1185997340</ListID>
<FullName>Parts and Supplies</FullName>
</ItemRef>
<Desc>Parts and Supplies: Netgear router</Desc>
<Quantity>1</Quantity>
<Rate>79.00</Rate>
<ClassRef>
<ListID>80000007-1186694551</ListID>
<FullName>Parts</FullName>
</ClassRef>
<Amount>79.00</Amount>
<SalesTaxCodeRef>
<ListID>80000001-1185469345</ListID>
<FullName>Tax</FullName>
</SalesTaxCodeRef>
</InvoiceLineRet>
</InvoiceRet>
<InvoiceRet>
<TxnID>ED59-1216758177</TxnID>
<TimeCreated>2008-07-22T16:22:57-05:00</TimeCreated>
<TimeModified>2008-07-26T11:21:48-05:00</TimeModified>
<EditSequence>1217085708</EditSequence>
<TxnNumber>11203</TxnNumber>
<CustomerRef>
<ListID>80000278-1209483158</ListID>
<FullName>Majestic Entries</FullName>
</CustomerRef>
<ARAccountRef>
<ListID>80000009-1185470478</ListID>
<FullName>Accounts Receivable</FullName>
</ARAccountRef>
<TemplateRef>
<ListID>80000019-1190228214</ListID>
<FullName>Compudoc</FullName>
</TemplateRef>
<TxnDate>2008-07-22</TxnDate>
<RefNumber>22479</RefNumber>
<BillAddress>
<Addr1>Majetic Entries</Addr1>
</BillAddress>
<BillAddressBlock>
<Addr1>Majetic Entries</Addr1>
</BillAddressBlock>
<IsPending>false</IsPending>
<IsFinanceCharge>false</IsFinanceCharge>
<DueDate>2008-07-22</DueDate>
<ShipDate>2008-07-22</ShipDate>
<Subtotal>839.00</Subtotal>
<ItemSalesTaxRef>
<ListID>8000004F-1185996977</ListID>
<FullName>NC 7.25%</FullName>
</ItemSalesTaxRef>
<SalesTaxPercentage>7.25</SalesTaxPercentage>
<SalesTaxTotal>33.64</SalesTaxTotal>
<AppliedAmount>0.00</AppliedAmount>
<BalanceRemaining>872.64</BalanceRemaining>
<IsPaid>false</IsPaid>
<IsToBePrinted>true</IsToBePrinted>
<IsToBeEmailed>false</IsToBeEmailed>
<CustomerSalesTaxCodeRef>
<ListID>80000001-1185469345</ListID>
<FullName>Tax</FullName>
</CustomerSalesTaxCodeRef>
<InvoiceLineRet>
<TxnLineID>ED5B-1216758177</TxnLineID>
<ItemRef>
<ListID>80000050-1185997340</ListID>
<FullName>Parts and Supplies</FullName>
</ItemRef>
<Desc>Parts and Supplies - Linksys Router</Desc>
<Quantity>1</Quantity>
<Rate>89.00</Rate>
<Amount>89.00</Amount>
<SalesTaxCodeRef>
<ListID>80000001-1185469345</ListID>
<FullName>Tax</FullName>
</SalesTaxCodeRef>
</InvoiceLineRet>
<InvoiceLineRet>
<TxnLineID>ED5C-1216758177</TxnLineID>
<Desc>Suspect that the phone switch is attempting to act as a DHCP server for the network. per Terry, the reason that the phone switch was on the network was to supply VOIP to the warehouse phone lines. This was not working and is no longer needed. We removed the connection between the phone switch and the network.</Desc>
</InvoiceLineRet>
<InvoiceLineRet>
<TxnLineID>ED5D-1216758177</TxnLineID>
<Desc>Removed the Netgear router and the D-Link router. The D-Link had lost all settings and we could not log into the Netgear even after resetting to factory defaults.</Desc>
</InvoiceLineRet>
<InvoiceLineRet>
<TxnLineID>ED5E-1216758177</TxnLineID>
<Desc>Installed a new Lnksys router to replace the D-Link and Netgear faulty routers.</Desc>
</InvoiceLineRet>
<InvoiceLineRet>
<TxnLineID>ED5F-1216758177</TxnLineID>
<Desc>Ensured that all computers were connecting properly. Ensured that all computers printed to the Savin printer correctly.</Desc>
</InvoiceLineRet>
<InvoiceLineRet>
<TxnLineID>ED60-1216758177</TxnLineID>
<Desc>Worked with Time Warner Cable to resolve customer location and static IP.</Desc>
</InvoiceLineRet>
<InvoiceLineRet>
<TxnLineID>ED64-1216758177</TxnLineID>
<ItemRef>
<ListID>80000028-1185470511</ListID>
<FullName>Labor:Non-Contract Labor Kareem</FullName>
</ItemRef>
<Desc>Analyzed and resolved Internet connectivity problems after loss of service from Time Warner Cable.</Desc>
<Quantity>3</Quantity>
<Rate>125.00</Rate>
<Amount>375.00</Amount>
<ServiceDate>2008-07-22</ServiceDate>
<SalesTaxCodeRef>
<ListID>80000002-1185469345</ListID>
<FullName>Non</FullName>
</SalesTaxCodeRef>
</InvoiceLineRet>
<InvoiceLineRet>
<TxnLineID>ED68-1216758177</TxnLineID>
<ItemRef>
<ListID>8000005D-1216758445</ListID>
<FullName>Labor:Non-Contract Labor Mike</FullName>
</ItemRef>
<Desc>Analyzed and resolved Internet connectivity problems after loss of service from Time Warner Cable.</Desc>
<Quantity>3</Quantity>
<Rate>125.00</Rate>
<Amount>375.00</Amount>
<ServiceDate>2008-07-22</ServiceDate>
<SalesTaxCodeRef>
<ListID>80000001-1185469345</ListID>
<FullName>Tax</FullName>
</SalesTaxCodeRef>
</InvoiceLineRet>
<InvoiceLineRet>
<TxnLineID>ED94-1216758177</TxnLineID>
<Desc>Terry called, cannot connect to internet. Everyone but Terry can connect. Terry is getting a 172 IP address on his laptop. Walked him through putting a static IP on his laptop so that he could be functional. I went to their site and talked with the NEC phone switch management company. They said the switch does not have DHCP capabilities. I could not duplicate Terry's issue using my laptop. The phone switch is now totally disconnected from the network since the VOIP setup for the warehouse was not functional. Validated that the TWC modem is not DHCP.</Desc>
<ServiceDate>2008-07-23</ServiceDate>
</InvoiceLineRet>
<InvoiceLineRet>
<TxnLineID>ED95-1216758177</TxnLineID>
<Desc>Requires further diagnostics on Friday the 25th (if Terry is available) - need his laptop on-site to diagnose the problem.</Desc>
</InvoiceLineRet>
<InvoiceLineRet>
<TxnLineID>EE30-1216758177</TxnLineID>
<Desc>Communicated with Terry on 7/24/2008 via email. He is using DHCP and connecting correctly. Removing the final connection from the phone switch to the network appears to have corrected the problem.</Desc>
<ServiceDate>2008-07-24</ServiceDate>
</InvoiceLineRet>
</InvoiceRet>
</TEST>Never mind. I figured it out.
-
I'm having trouble getting subordinate tag data out of this structure:
<CASE_BATCH>
<CASEDETAIL>
<HEADER>
<PERSON_ID>214339</PERSON_ID>
</HEADER>
<ASSOC>
<AP_ID>166646</AP_ID>
<AP_NAME>
<LASTNAME>TEST</LASTNAME>
<FIRSTNAME>TEST</FIRSTNAME>
</AP_NAME>
</ASSOC>
<ASSOC>
<AP_ID>166647</AP_ID>
<AP_NAME>
<LASTNAME>TEST2</LASTNAME>
<FIRSTNAME>TEST2</FIRSTNAME>
</AP_NAME>
</ASSOC>
</CASEDETAIL>
</CASEBATCH>
One of the many XQueries I've tried is:
select b.*
from eachFile,
xmltable('/CASE_BATCH/CASEDETAIL'
passing eachfile.mytype
columns
extnum number PATH '/CASEDETAIL/HEADER/PERSON_ID') A,
xmltable('CASE_BATCH/CASEDETAIL'
passing eachfile.mytype
columns
extnum number PATH '/CASEDETAIL/HEADER/PERSON_ID',
id Number Path '/CASEDETAIL/ASSOC/AP_ID',
lastname varchar2(50) '/CASEDETAIL/ASSOC/AP_NAME/LASTNAME',
firstname varchar2(50) '/CASEDETAIL/ASSOC/AP_NAME/FIRSTNAME') b
where a.extnum = 214339 and
a.extnum = b.extnum
If I leave the b.extnum out of it the column and where clause, and set the xmlTable path down to 'CASE_BATCH/CASEDETAIL/ASSOC' and the b columns path as
'/ASSOC/PERSON_ID' then I return all data, regardless of where in the file it's located. That makes sense because I don't have the extnum in the where clause to filter out unrelated tags.
How can I make this work?Here is an example of using the XMLTable() function to create a master-detail view over multiple levels of your XML data. This PURCHASEORDER table can be found in the OE (order entry) sample schema when you create a new database instance with DBCA. Notice the passing clause (i.e., passing m.items ) in the second XMLTable() function.
Send me email (geoff dot lee at oracle dot com) directly if you still have problems.
Regards,
Geoff
SQL> create or replace view PO_MASTER_DETAIL_VIEW
2 as
3 select m.REFERENCE,m.REQUESTOR,m.USERID,m.COSTCENTER,item.*
4 from PO_SL_BIX_TABLE,
5 xmltable
6 ('/PurchaseOrder' passing object_value
7 COLUMNS
8 REFERENCE varchar2(30) path 'Reference',
9 REQUESTOR varchar2(128) path 'Requestor',
10 USERID varchar(10) path 'User',
11 COSTCENTER varchar2(4) path 'CostCenter',
12 ITEMS xmltype path 'LineItems'
13 ) m,
14 xmltable
15 ('/LineItems/LineItem' passing m.items
16 COLUMNS
17 ITEMNO number(38) path '@ItemNumber',
18 DESCRIPTION varchar2(1024) path 'Description',
19 PARTNO varchar2(56) path 'Part/@Id',
20 QUANTITY number(38) path 'Part/@Quantity',
21 UNITPRICE number(12,2) path 'Part/@UnitPrice'
22 ) item
23 /
View created.
SQL>
SQL> describe PO_MASTER_DETAIL_VIEW
Name Null? Type
REFERENCE VARCHAR2(30)
REQUESTOR VARCHAR2(128)
USERID VARCHAR2(10)
COSTCENTER VARCHAR2(4)
ITEMNO NUMBER(38)
DESCRIPTION VARCHAR2(1024)
PARTNO VARCHAR2(56)
QUANTITY NUMBER(38)
UNITPRICE NUMBER(12,2)
SQL> select REFERENCE, ITEMNO, PARTNO
2 from PO_MASTER_DETAIL_VIEW
3 where USERID = 'SBELL'
4 and PARTNO in ( '37429121726', '37429122129', '715515009058' )
5 /
REFERENCE ITEMNO PARTNO
SBELL-20021009123335280PDT 7 715515009058
SBELL-20021009123335280PDT 11 37429121726
SBELL-20021009123338304PDT 9 37429122129
SBELL-20021009123336331PDT 2 715515009058
SBELL-2002100912333763PDT 19 37429122129
SBELL-2002100912333601PDT 1 715515009058
SBELL-20021009123336532PDT 2 37429121726
SBELL-20021009123338204PDT 12 715515009058
8 rows selected. -
Create Relational View got error: ORA-19276: XPST0005 - XPath step specifie
Hi expert,
I am using Oracle 11.2.0.1.0 XML DB.
I am successfully registered schema and generated a table DOCUMENT.
I have succfully inserted 12 .xml files to this table.
SQL> SELECT OBJECT_VALUE FROM document;
OBJECT_VALUE
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet href="http://www.accessdata.fda.gov/spl/stylesheet/spl.xsl" type="text/xsl"?>
<document xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 http://localhost:8080/home/DEV/xsd/spl.xsd">
<id root="03d6a2cd-fdda-4fe1-865d-da0db9212f34"/>
<code code="51725-0" codeSystem="2.16.840.1.113883.6.1" displayName="ESTABLISHMENT REGISTRATION"/>
</component>
</document>
then I tried to create a create Relational View base on one inserted .xml file I got error:
ERROR at line 3:
ORA-19276: XPST0005 - XPath step specifies an invalid element/attribute name: (document)
is there anyone know what was wrong?
Thanks a lot!
Cow
Edited by: Cow on Feb 15, 2011 8:58 PM
Edited by: Cow on Feb 21, 2011 6:59 AMThese kinds of issues, you will have to solve by joining multiple resultsets or passing fragments to the next XMLTABLE statement and building redundancy via the ORDINALITY clause (which results a NUMBER datatype)
For example
A "transaction" can have multiple "status"ses which can have multiple "reason"s
WITH XTABLE
AS
(SELECT xmltype('<TRANSACTION>
<PFL_ID>123456789</PFL_ID>
<PMI_ID>1</PMI_ID><PII_ID>1</PII_ID>
<ID>1</ID>
<INSTR_ID>MARCO_003</INSTR_ID>
<E_TO_E_ID>MARCO_004</E_TO_E_ID>
<INSTD_AMT>10</INSTD_AMT>
<INSTD_AMT_CCY>EUR</INSTD_AMT_CCY>
<STATUS>
<PFL_ID>123456789</PFL_ID>
<PMI_ID>1</PMI_ID><PII_ID>1</PII_ID>
<TXI_ID>1</TXI_ID>
<ID>1</ID>
<PMT_TX_STS_UTC_DT>2011-02-15</PMT_TX_STS_UTC_DT>
<REASON>
<ID>1000</ID>
<STS_RSN_PRTRY>MG001</STS_RSN_PRTRY>
</REASON>
<REASON>
<ID>2000</ID>
<STS_RSN_PRTRY>IS000</STS_RSN_PRTRY>
</REASON>
</STATUS>
</TRANSACTION>') as XMLCOLUMN
FROM DUAL
SELECT STS_ID as STATUS_ID,
STS_PFL_ID,
STS_PMI_ID,
STS_TXI_ID,
RSN_ID as REASON_ID,
RSN_STS_RSN_PRTRY,
RSN_XML_POS as POSITION
FROM XTABLE
, XMLTABLE ('/TRANSACTION/STATUS'
PASSING XMLCOLUMN
COLUMNS
STS_PFL_ID NUMBER(10) path 'PFL_ID'
, STS_PMI_ID NUMBER(10) path 'PMI_ID'
, STS_TXI_ID NUMBER(10) path 'TXI_ID'
, STS_ID VARCHAR2(10) path 'ID'
, XML_REASONS XMLTYPE path 'REASON'
) sts
, XMLTABLE ('/REASON'
PASSING sts.XML_REASONS
COLUMNS
RSN_XML_POS FOR ORDINALITY
, RSN_ID VARCHAR2(10) path 'ID'
, RSN_STS_RSN_PRTRY VARCHAR2(10) path 'STS_RSN_PRTRY'
) rsnWill give you the following output (in your case DON"T forget to buildin the namespace references)
SQL> WITH XTABLE
2 AS
3 (SELECT xmltype('<TRANSACTION>
4 <PFL_ID>123456789</PFL_ID>
5 <PMI_ID>1</PMI_ID><PII_ID>1</PII_ID>
6 <ID>1</ID>
7 <INSTR_ID>MARCO_003</INSTR_ID>
8 <E_TO_E_ID>MARCO_004</E_TO_E_ID>
9 <INSTD_AMT>10</INSTD_AMT>
10 <INSTD_AMT_CCY>EUR</INSTD_AMT_CCY>
11 <STATUS>
12 <PFL_ID>123456789</PFL_ID>
13 <PMI_ID>1</PMI_ID><PII_ID>1</PII_ID>
14 <TXI_ID>1</TXI_ID>
15 <ID>1</ID>
16 <PMT_TX_STS_UTC_DT>2011-02-15</PMT_TX_STS_UTC_DT>
17 <REASON>
18 <ID>1000</ID>
19 <STS_RSN_PRTRY>MG001</STS_RSN_PRTRY>
20 </REASON>
21 <REASON>
22 <ID>2000</ID>
23 <STS_RSN_PRTRY>IS000</STS_RSN_PRTRY>
24 </REASON>
25 </STATUS>
26 </TRANSACTION>') as XMLCOLUMN
27 FROM DUAL
28 )
29 SELECT STS_ID as STATUS_ID,
30 STS_PFL_ID,
31 STS_PMI_ID,
32 STS_TXI_ID,
33 RSN_ID as REASON_ID,
34 RSN_STS_RSN_PRTRY,
35 RSN_XML_POS as POSITION
36 FROM XTABLE
37 , XMLTABLE ('/TRANSACTION/STATUS'
38 PASSING XMLCOLUMN
39 COLUMNS
40 STS_PFL_ID NUMBER(10) path 'PFL_ID'
41 , STS_PMI_ID NUMBER(10) path 'PMI_ID'
42 , STS_TXI_ID NUMBER(10) path 'TXI_ID'
43 , STS_ID VARCHAR2(10) path 'ID'
44 , XML_REASONS XMLTYPE path 'REASON'
45 ) sts
46 , XMLTABLE ('/REASON'
47 PASSING sts.XML_REASONS
48 COLUMNS
49 RSN_XML_POS FOR ORDINALITY
50 , RSN_ID VARCHAR2(10) path 'ID'
51 , RSN_STS_RSN_PRTRY VARCHAR2(10) path 'STS_RSN_PRTRY'
52 ) rsn
53 ;
STATUS_ID STS_PFL_ID STS_PMI_ID STS_TXI_ID REASON_ID RSN_STS_RS POSITION
1 123456789 1 1 1000 MG001 1
1 123456789 1 1 2000 IS000 2
2 rows selected.If I wouldn't have done that then I would have got your result which fails with your error:
- ORA-19279 - XQuery dynamic type mismatch: expected singleton sequence - got multi-item sequence
SQL> WITH XTABLE
2 AS
3 (SELECT xmltype('<TRANSACTION>
4 <PFL_ID>123456789</PFL_ID>
5 <PMI_ID>1</PMI_ID><PII_ID>1</PII_ID>
6 <ID>1</ID>
7 <INSTR_ID>MARCO_003</INSTR_ID>
8 <E_TO_E_ID>MARCO_004</E_TO_E_ID>
9 <INSTD_AMT>10</INSTD_AMT>
10 <INSTD_AMT_CCY>EUR</INSTD_AMT_CCY>
11 <STATUS>
12 <PFL_ID>123456789</PFL_ID>
13 <PMI_ID>1</PMI_ID><PII_ID>1</PII_ID>
14 <TXI_ID>1</TXI_ID>
15 <ID>1</ID>
16 <PMT_TX_STS_UTC_DT>2011-02-15</PMT_TX_STS_UTC_DT>
17 <REASON>
18 <ID>1000</ID>
19 <STS_RSN_PRTRY>MG001</STS_RSN_PRTRY>
20 </REASON>
21 <REASON>
22 <ID>2000</ID>
23 <STS_RSN_PRTRY>IS000</STS_RSN_PRTRY>
24 </REASON>
25 </STATUS>
26 </TRANSACTION>') as XMLCOLUMN
27 FROM DUAL
28 )
29 SELECT STS_ID as STATUS_ID,
30 STS_PFL_ID,
31 STS_PMI_ID,
32 STS_TXI_ID,
33 RSN_ID as REASON_ID,
34 RSN_STS_RSN_PRTRY
35 FROM XTABLE
36 , XMLTABLE ('/TRANSACTION/STATUS'
37 PASSING XMLCOLUMN
38 COLUMNS
39 STS_PFL_ID NUMBER(10) path 'PFL_ID'
40 , STS_PMI_ID NUMBER(10) path 'PMI_ID'
41 , STS_TXI_ID NUMBER(10) path 'TXI_ID'
42 , STS_ID VARCHAR2(10) path 'ID'
43 , RSN_ID VARCHAR2(10) path 'REASON/ID'
44 , RSN_STS_RSN_PRTRY VARCHAR2(10) path 'REASON/STS_RSN_PRTRY'
45 ) rsn;
</REASON>
ERROR at line 24:
ORA-19279: XQuery dynamic type mismatch: expected singleton sequence - got
multi-item sequenceHTH
Edited by: Marco Gralike on Feb 16, 2011 12:12 PM -
Oracle 10.2.0.3 apparent XML bug
A very simply query using 'string-join' fails but works with 'concat'. The error we get is: ORA-19112: error raised during evaluation: java.lang.OutOfMemoryError
The basic query is (its attempting to join "_A" to about 5000 rows - see the query below) :
xquery for $x in ora:view("USER_A","TABLE_A")/ROW
where $x/ITEM_ID/text() ne 999
return
<a>{string-join(($x/ITEM_ID/text(),"A"),"_")}</a>
Is this a bug and will it be fixed when 10.2.0.4 comes out?
Thankyou for your assistanceI think you compare apples with oranges. string-join and concat behave very differently and are not interchangeable:
michaels> CREATE TABLE table_a
AS SELECT '999' item_id FROM DUAL UNION ALL
SELECT '997' item_id FROM DUAL UNION ALL
SELECT '998' item_id FROM DUAL UNION ALL
SELECT '999' item_id FROM DUAL
Table created.
michaels> select * from XMLTable('for $x in ora:view("TABLE_A")/ROW
where $x/ITEM_ID/text() ne "999"
return <i>{string-join(($x/ITEM_ID/text(),"A"),"_")}</i>')
COLUMN_VALUE
<i>997_A</i>
<i>998_A</i>
2 rows selected.
michaels> select * from XMLTable('for $x in ora:view("TABLE_A")/ROW
where $x/ITEM_ID/text() ne "999"
return <i>{concat(($x/ITEM_ID/text(),"A"),"_")}</i>')
Error at line 1
ORA-19279: XQuery dynamic type mismatch: expected singleton sequence - got multi-item sequence
michaels> select * from XMLTable('for $x in ora:view("TABLE_A")/ROW
where $x/ITEM_ID/text() ne "999"
return <i>{concat($x/ITEM_ID/text(),"A","_")}</i>')
COLUMN_VALUE
<i>997A_</i>
<i>998A_</i>
2 rows selected. -
I have below xml in oracle table, how to extract partial address data "10 Otterburn Gardens, ISLEWORTH, Middlesex TW4 5JJ" using sql
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<qas:QASearchResult xmlns:qas="http://www.qas.com/web-2009-08" VerifyLevel="None">
<qas:QAPicklist AutoFormatSafe="true">
<qas:FullPicklistMoniker>0_MGBRFQbdBwAAAAABAQEAAQAAAADfKULSACEYAgAAAAAAMTYAAP..ZAAAAAD.....AAAAAAAAAAA-</qas:FullPicklistMoniker>
<qas:PicklistEntry FullAddress="true">
<qas:Moniker>0XOGBRFQbdBwAAAAABAwEAAAAA3ylC0gAhGAIAAAAAADE2AAD..2QAAAAA.....wAAAAAAAAAAADE2IE90dGVyYnVybiBHYXJkZW5zLCBUVzcgNUpKAA--</qas:Moniker>
<qas:PartialAddress>10 Otterburn Gardens, ISLEWORTH, Middlesex TW4 5JJ</qas:PartialAddress>
<qas:Picklist>16 Otterburn Gardens, ISLEWORTH, Middlesex</qas:Picklist>
<qas:Postcode>TW7 5JJ</qas:Postcode>
<qas:Score>100</qas:Score>
</qas:PicklistEntry>
<qas:Prompt>Enter selection</qas:Prompt>
<qas:Total>1</qas:Total>
</qas:QAPicklist>
</qas:QASearchResult>
</soap:Body>
</soap:Envelope>Also, I can see here -- ORA-19279: XPTY0004 - XQuery dynamic type mismatch: expected singleton sequence - got multi-item sequence
that you have used another technique XMLNamespaces() for the same.
select x.*
from abc t
, xmltable(
xmlnamespaces(
default 'urn:swift:xsd:fin.970.2011'
, 'urn:swift:xsd:mtmsg.2011' as "ns0"
, '/ns0:FinMessage/ns0:Block4/Document/MT970/F61a/F61'
passing t.col1
columns F61ValueDate Varchar(40) Path 'ValueDate'
, DebitCreditMark Varchar(40) Path 'DebitCreditMark'
, Amount Varchar(40) Path 'Amount'
, TransactionType Varchar(40) Path 'TransactionType'
, IdentificationCode Varchar(40) Path 'IdentificationCode'
, ReferenceForTheAccountOwner Varchar(40) Path 'ReferenceForTheAccountOwner'
, SupplementaryDetails Varchar(40) Path 'SupplementaryDetails'
) x;
What you are trying to do here? and why that "default" namespace?
Also, I'll also go through the docs in this meantime.
-- Ranit -
Extracting data from XMLType field
Sorry, I don't know XMLQuery very well, this is probably a simple question. I'm trying to extract data into a tablular form from an XMLTYPE field. I'll use the following example to illustrate my question:
WITH a as (
select xmltype('
<bugStatus>
<status>
<bugCode>111</bugCode>
<bug number="12345" description="Low severity bug"/>
</status>
<status>
<bugCode>222</bugCode>
<bug number="67890" description="High severity bug"/>
</status>
</bugStatus>
') xmldata from dual)
SELECT x.*
FROM a, xmltable('bugStatus/status'
passing a.xmldata columns
status_code number path 'bugCode'
) x;
Running that code block extracts the "bugCode" fields successfully. But I'd like to also similarly extract the "bug number" and "description" fields. Ideally as independent columns. But even if only as a single line showing "bug number=.... description=....." I could then still parse it with SQL.
Can someone please point me in the right direction of how I can also extract that additional data?
Thanks!Thanks Marco, that was a great and simple solution to my original question.
However let me change the data slightly. I've tried to do something similar with this slightly modified XML data and I think I'm close, but not quite there. Can you assist with this new scenario?
WITH a as (
select xmltype('
<bugStatus>
<bugCode REF_ID="XYZ">
<status>
<bug number="12345" description="Low severity bug"/>
<bug number="67890" description="High severity bug"/>
</status>
</bugCode>
</bugStatus>
') xmldata from dual)
SELECT /*x.bugCode,*/ y.bugNumber, y.bugDescription
FROM a,
xmltable('/bugStatus'
PASSING a.xmldata
COLUMNS
bugCode char(3) path 'bugCode/@REF_ID',
mystatus xmltype path 'bugCode/status'
) x,
xmltable('/status'
PASSING x.mystatus
COLUMNS
--row_number for ordinality,
bugNumber number path 'bug/@number',
bugDescription varchar2(80) path 'bug/@description'
) y;
I think I'm close on this one but still getting the error:
ORA-19279: XPTY0004 - XQuery dynamic type mismatch: expected singleton sequence - got multi-item sequence
Thank you! -
Issue with SQL for the XMLTABLE
Hi ,
Here is what I want to Achieve :
This is my XSD :
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://my-company.com/namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://my-company.com/namespace" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="NOTE" type="NOTEType">
<xs:annotation>
<xs:documentation>Root Element</xs:documentation>
</xs:annotation>
</xs:element>
<xs:complexType name="NOTEType">
<xs:sequence>
<xs:element name="TO" type="SENDERTYPE"/>
<xs:element name="FROM" type="RECEIVERTYPE"/>
<xs:element name="HEADING" type="HEADINGTYPE"/>
<xs:element name="BODY" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="SENDERTYPE">
<xs:sequence>
<xs:element name="COMPANY" type="xs:string"/>
<xs:element name="INDIVIDUAL" type="xs:string" maxOccurs="unbounded"/>
<xs:element name="ORGANIZATION" type="xs:string"/>
<xs:element name="DEPARTMENT" type="xs:string" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="RECEIVERTYPE">
<xs:sequence>
<xs:element name="COMPANY" type="xs:string"/>
<xs:element name="INDIVIDUAL" type="xs:string" maxOccurs="unbounded"/>
<xs:element name="ORGANIZATION" type="xs:string"/>
<xs:element name="DEPARTMENT" type="xs:string" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="HEADINGTYPE">
<xs:sequence>
<xs:element name="SINGLELINE">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="200"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="MULTILINE" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
This is my XML Document : (I Have 3 ,more similar Similar XML Files in the NOTES table)
<?xml version="1.0" encoding="UTF-8"?>
<NOTE xmlns="http://my-company.com/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://my-company.com/namespace file:///C:/Documents%20and%20Settings/saoa/Desktop/MY%20WORK/XML/NOTE.xsd">
<TO>
<COMPANY>United Guaranty</COMPANY>
<INDIVIDUAL/>
<ORGANIZATION/>
<DEPARTMENT/>
</TO>
<FROM>
<COMPANY/>
<INDIVIDUAL>Aniket Sao</INDIVIDUAL>
<INDIVIDUAL>Monit Sao</INDIVIDUAL>
<INDIVIDUAL>Yeshwant Sao</INDIVIDUAL>
<INDIVIDUAL>Dashrath Sao</INDIVIDUAL>
<ORGANIZATION/>
<DEPARTMENT/>
</FROM>
<HEADING>
<SINGLELINE>Just Testing XML</SINGLELINE>
<MULTILINE/>
</HEADING>
<BODY>This is just to test of the XML works fine</BODY>
</NOTE>
The Output which I'm trying to get is
NOTESID - TOCOMPANY - TOINDIVIDUAL - TOORGANIZATION - TODEPARTMENT- FROMCOMPANY- FROMINDIVIDUAL- FROMORGANIZATION- FROMDEPARTMENT- SINGLEHEADING- MULTIHEADING- BODY-
1- United Guaranty- NULL- NULL- NULL- NULL- Aniket Sao- NULL- NULL- Just Testing XML- NULL- This is just to test of the XML works fine-
2- United Guaranty- NULL- NULL- NULL- NULL- Monit Sao- NULL- NULL- Just Testing XML- NULL- This is just to test of the XML works fine-
3- United Guaranty- NULL- NULL- NULL- NULL- Yeshwant Sao- NULL- NULL- Just Testing XML- NULL- This is just to test of the XML works fine
4- United Guaranty- NULL- NULL- NULL- NULL- Dashrath Sao- NULL- NULL- Just Testing XML- NULL- This is just to test of the XML works fine
Here is the Query I Fire :
SELECT
NOTES2."TO",
NOTES2."FROM",
NOTES2."HEADING",
NOTES2."BODY"
FROM NOTES,
XMLTABLE('/NOTE'
PASSING NOTES.NOTESXMLCOL
COLUMNS
"TO" varchar2(50) PATH '/NOTE/TO',
"FROM" varchar2(50) PATH '/NOTE/FROM',
"HEADING" varchar2(50) PATH '/NOTE/HEADING',
"BODY" varchar2(300) PATH '/NOTE/BODY')
NOTES2;
This is the Result I get
TO FROM HEADING BODY
United Guaranty Aniket SaoMonit SaoYeshwant SaoDashrath Sao Just Testing XML This is just to test of the XML works fine
I want to split up the Multiple occurance of the node into different rows. how to do that ?
I Event tried this ;
SELECT NOTESID NOTES,
NOTES2."TOCOMPANY",
NOTES2."TOINDIVIDUAL",
NOTES2."TOORGANIZATION",
NOTES2."TODEPARTMENT",
NOTES2."FROMCOMPANY",
NOTES2."FROMINDIVIDUAL",
NOTES2."FROMORGANIZATION",
NOTES2."FROMDEPARTMENT",
NOTES2."SINGLEHEADING",
NOTES2."MULTIHEADING",
NOTES2."BODY"
FROM NOTES,
XMLTABLE('/NOTE'
PASSING NOTES.NOTESXMLCOL
COLUMNS
"TOCOMPANY" varchar2(50) PATH '/NOTE/TO/COMPANY',
"TOINDIVIDUAL" varchar2(50) PATH '/NOTE/TO/INDIVIDUAL',
"TOORGANIZATION" varchar2(50) PATH '/NOTE/TO/ORGANIZATION',
"TODEPARTMENT" varchar2(50) PATH '/NOTE/TO/DEPARTMENT',
"FROMCOMPANY" varchar2(50) PATH '/NOTE/FROM/COMPANY',
"FROMINDIVIDUAL" varchar2(50) PATH '/NOTE/FROM/INDIVIDUAL',
"FROMORGANIZATION" varchar2(50) PATH '/NOTE/FROM/ORGANIZATION',
"FROMDEPARTMENT" varchar2(50) PATH '/NOTE/FROM/DEPARTMENT',
"SINGLEHEADING" varchar2(50) PATH '/NOTE/HEADING/SINGLELINE',
"MULTIHEADING" varchar2(50) PATH '/NOTE/HEADING/MULTILINE',
"BODY" varchar2(300) PATH '/NOTE/BODY')
NOTES2;
I Get
ORA-19279: XPTY0004 - XQuery dynamic type mismatch: expected singleton sequence - got multi-item sequence
19279. 00000 - "XQuery dynamic type mismatch: expected singleton sequence - got multi-item sequence"
*Cause: The XQuery sequence passed in had more than one item.
*Action: Correct the XQuery expression to return a single item sequence.
Please help.
Thanks,
AniketHi,
Note for next time : Oracle XML-related questions are best posted in the {forum:id=34} forum.
The exact database version would be appreciated too.
Repeating elements are typically handled by adding a nested XMLTable to shred them into relational rows :
SELECT x1.to_company
, x1.to_individual
, x1.to_organization
, x1.to_department
, x1.from_company
, x2.from_individual
, x1.from_organization
, x1.from_department
, x1.single_heading
, x1.multi_heading
, x1.body
FROM notes t
, XMLTable(
XMLNamespaces(default 'http://my-company.com/namespace')
, '/NOTE'
passing t.notesxmlcol
columns
to_company varchar2(50) PATH 'TO/COMPANY'
, to_individual varchar2(50) PATH 'TO/INDIVIDUAL'
, to_organization varchar2(50) PATH 'TO/ORGANIZATION'
, to_department varchar2(50) PATH 'TO/DEPARTMENT'
, from_company varchar2(50) PATH 'FROM/COMPANY'
, from_individuals xmltype PATH 'FROM/INDIVIDUAL'
, from_organization varchar2(50) PATH 'FROM/ORGANIZATION'
, from_department varchar2(50) PATH 'FROM/DEPARTMENT'
, single_heading varchar2(50) PATH 'HEADING/SINGLELINE'
, multi_heading varchar2(50) PATH 'HEADING/MULTILINE'
, body varchar2(300) PATH 'BODY'
) x1
, XMLTable(
XMLNamespaces(default 'http://my-company.com/namespace')
, '/INDIVIDUAL'
passing x1.from_individuals
columns
from_individual varchar2(50) PATH 'text()'
) x2
;I guess it's probably not your actual schema, but having unwrapped unbounded elements in the middle of the document doesn't make it a good candidate for a relational output.
For example, what output would you require if, at the same time, there are multiple occurrences of FROM/DEPARTMENT, FROM/INDIVIDUAL, TO/DEPARTMENT and TO/INDIVIDUAL?
Maybe you are looking for
-
X-path query to get all versions of a node at a given path in JSP
hi need a xpath query so that i can list all the versions of a selected node which can be used for restoring the version to that particular one??
-
Problem with select query when it returns a NULL value
Hi all, I have a d/b table called QMEL and i picked VBELN from that table. Now if the VBELN value in that table is NULL i have to wtite an if condition. Can i say it like this IF VBELN = ' '. write: enter into the if condition. ELSE. write: enter int
-
Psadmin list-dp : xml output is encoded with environment locale encoding
I am building some scripts to help me administer desktop profiles, providers jsp files, and others. Thoses scripts use the psadmin command. I have hit what seems to me an unexpected behavior, when trying to download a desktop profile from a script :
-
How to Delete a Database on ASM
I am trying to delete a database which seems to be on ASM but I get the errors below. I have limited exposure on ASM so not sure how to proceed. Can someone help? $ dbca -silent -deleteDatabase -responseFile dbca_response.rsp ORA-01078: failure in pr
-
Javascript error throws the portal theme configuration page
General Description: Javascript error and jump to the portal theme configuration page EP: NW04s SP12 including KMC We have a problem when we entry to the portal, a javascript error happens and immediately jumps to the portal theme configuration page.