Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Optional XML Tags - in XMLTABLE Function- PASSING Clause

AshokramNov 18 2016 — edited Nov 22 2016

Hello all,

Thanks in advance.

I am using XMLTABLE function for parsing an XML which carries relational data to be inserted in some 14 tables.

This is a sample of the XMLTABLE SELECT query I am using:

SELECT Inch.InterchangeRefno, Inch.FileName, Txns.TransactionSeq

            FROM XMLTABLE (

                    '/BookingBL'

                    PASSING XMLTYPE (BFILENAME ('XMLREAD', 'Sample_file.xml'),

                                     NLS_CHARSET_ID ('UTF8'))

                    COLUMNS Interchange XMLTYPE PATH 'Interchange',

                            Transactions XMLTYPE PATH 'Transactions') Booking,

                 XMLTABLE (

                    '/Interchange'

                    PASSING Booking.Interchange

                    COLUMNS InterchangeRefno VARCHAR2 (100) PATH 'InterchangeRefno',

                            FileName VARCHAR2 (100) PATH 'FileName') Inch,

                 XMLTABLE ('/Transactions/Transaction'

                           PASSING Booking.Transactions

                           COLUMNS TransactionSeq NUMBER PATH '@SeqNo') Txns;

In this query, If the  '/Interchange' tag is not coming in the XML (since the XML is formed based on a incoming EDI text data, some data may come or not), then the entire SELECT query is returning no data.

My requirement here is, even if tags which are specified in the XMLTABLE('tag'   PASSING..... clause is absent, the query should return the data from the previous parsing alone (in my case interchange detail alone).

I browsed a lot for a solution, but I couldn't find the solution for this. i.e. optional tags in XMLTABLE PASSING clause.

Please light me in this.

Thanks again.

This post has been answered by odie_63 on Nov 18 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 20 2016
Added on Nov 18 2016
3 comments
1,374 views