Use of xmltable

Hello

I have the following XML in the tmp_xml of the tmp_table table column:

" < = xmlns:env env:Envelope ' http://schemas.xmlsoap.org/SOAP/envelope/ ">

< env:Header / >

< env:Body >

" < its: getCriteriaNamesListResponse xmlns: its = ' http://session.kernel.CMP.com/ ">

< return >

< element > CRITERIA_UID < / item >

< element > CRITERIA_LAST_NAME < / item >

< element > CRITERIA_MEXI_ADDRESS < / item >

< element > CRITERIA_FIRST_NAME < / item >

< element > NONE < / item >

< element > CRITERIA_NISS < / item >

< element > CRITERIA_INAMI < / item >

< / return >

< / its: getCriteriaNamesListResponse >

< / env:Body >

< / env:Envelope >

I want to extract all the sequences of the "point".

This selection back 1 line empty:

Select extractvalue (value (b), ' / env:Envelope / env:Body / / return/point ',' xmlns:env = 'http://schemas.xmlsoap.org/soap/envelope/' ", xmlns: its ="http://session.kernel.mexi.com/"'") point

tmp_table, a table (xmlsequence (extract (a.tmp_xml, ' / / return'))) b

The select statement returns 7 blank lines:

Select article extractvalue (value (b), ' / back/item ")

tmp_table, a table (xmlsequence (extract (a.tmp_xml, ' / env:Envelope / env:Body / / return/point ',' xmlns:env = "http://schemas.xmlsoap.org/soap/envelope/", xmlns: its = "http://session.kernel.mexi.com/"'))) b


Could someone give me a tip how to retrieve the values of 'element '?

Best regards, Hans

Looks like you hit an old bug in 10g.

Try with the CURSOR_SHARING_EXACT indicator:

Select / * + CURSOR_SHARING_EXACT * / x.*

of tmp_table t

xmltable)

XmlNamespaces)

"http://schemas.xmlsoap.org/soap/envelope/" as "env".

, 'http://session.kernel.cmp.com/' as 'his '.

)

, ' / env:Envelope / env:Body / its: getCriteriaNamesListResponse/return/point '

in passing t.tmp_xml

varchar2 columns (30) the point road '.'

) x ;

or you can also go back to the old method (now obsolete in Oracle 11 and following):

SQL > select extractvalue (value (x), 'point') as element

tmp_table 2 t

3, table)

4 xmlsequence)

5. extract)

6 t.tmp_xml

7, ' / env:Envelope / env:Body / its: getCriteriaNamesListResponse/return/point '

"' 8, ' xmlns:env ="http://schemas.xmlsoap.org/soap/envelope/"

"9 xmlns: its ="http://session.kernel.cmp.com/' "."

10           )

11         )

(12) x;

AGENDA

--------------------------------------------------------------------------------

CRITERIA_UID

CRITERIA_LAST_NAME

CRITERIA_MEXI_ADDRESS

CRITERIA_FIRST_NAME

NONE

CRITERIA_NISS

CRITERIA_INAMI

7 selected lines

Tags: Oracle Development

Similar Questions

  • Tuning sql by using the xmltable() function.

    Hi all

    With Oracle 10g 10.2.0.1, Solaris 10

    Under query very slow... for 25 k at all just 100 KB xml documents.
    SELECT HQ_FLAG ,
        REGSTR_FLAG ADDRESS_STAMP ,
        BUILDING ,
        street_address ,
        PO_BOX ,
        CITY ,
        STATE_REGION ,
        POSTAL_CODE ,
        country_code ,
        a.ORG_ID
    FROM common.BID_XML_DATA a,
        xmltable( 'for $i in IntegrationBID/Organization   
    return <Row OrgID="{$i/OrgID}">{ $i/OrgGeneralInformation/Address } </Row>' passing xml_data 
    columns 
    hq_flag varchar2(5) path 'Address/@HeadquartersFlag', 
    regstr_flag varchar2(5) path 'Address/@RegisteredFlag', 
    address_stamp varchar(10) path 'Address/@LastUpdated', 
    building varchar(40) path 'Address/Building', 
    street_address varchar(40) path 'Address/StreetAddress', 
    po_box varchar(40) path 'Address/POBox', 
    city varchar(40) path 'Address/City', 
    state_region character(3) path 'Address/StateOrRegion', 
    postal_code varchar(10) path 'Address/PostalCode', 
    country_code character(3) path 'Address/Country/@Code', 
    Org_ID NUMBER(19) path '@OrgID') b;
    
    SQL> desc common.BID_XML_DATA
     Name                                                                                Null?    Type
     ----------------------------------------------------------------------------------- -------- --------------------------------------------------------
     XML_DATA                                                                                     XMLTYPE
     BID_INSERT_STAMP                                                                             DATE
     RN                                                                                           NUMBER(5)
     ORG_ID                                                                                       NUMBER(19)
    
    --------------------------------------------------------------------------------------------------------------
    | Id  | Operation                           | Name                   | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                    |                        |  8168 |   749K|    27   (0)| 00:00:01 |
    |   1 |  MERGE JOIN CARTESIAN               |                        |  8168 |   749K|    27   (0)| 00:00:01 |
    |   2 |   TABLE ACCESS FULL                 | BID_XML_DATA           |     1 |    92 |     3   (0)| 00:00:01 |
    |   3 |   BUFFER SORT                       |                        |  8168 | 16336 |    24   (0)| 00:00:01 |
    |   4 |    COLLECTION ITERATOR PICKLER FETCH| XMLSEQUENCEFROMXMLTYPE |       |       |            |          |
    --------------------------------------------------------------------------------------------------------------
    I tried to create indexes on this table... but in vain...
    SQL> CREATE INDEX common.XML_DATA_IDX ON common.BID_XML_TABLE (xml_data)
      2  INDEXTYPE IS XDB.XMLIndex
    PARAMETERS ('PATHS (INCLUDE (IntegrationBID/Organization/OrgID
      3    4                                                  IntegrationBID/Organization/OfficerInformation/Officer/ID
      5                                                  IntegrationBID/Organization/WebLinkInfo
      6  IntegrationBID/Organization/FilingSpecificInformation/FilingInformation/CompanyID
    IntegrationBID/Organization/FilingSpecificInformation/FilingInformation/ContactInfo
      7    8        IntegrationBID/Organization/FilingSpecificInformation/FilingInformation/Advisors/TransferAgent/Name
      9        IntegrationBID/Organization/OfficerInformation/Officer/PersonInformation/Name
     10        IntegrationBID/Organization/OfficerInformation/Officer/OfficerContacts
     11        IntegrationBID/Organization/OfficerInformation/Officer/PersonInformation/EducationHistory/Education
     12        IntegrationBID/Organization/OfficerInformation/Officer/PositionInformation/TenureDates
     13        IntegrationBID/Organization/OfficerInformation/Officer/PositionInformation/Titles/Designation
     14        IntegrationBID/Organization/OfficerInformation/Officer/PositionInformation/CommitteeMemberships/Committee
          IntegrationBID/Organization/OfficerInformation/Officer/SalaryInformation/CompensationPeriod
     15   16                              )
     17                      NAMESPACE MAPPING
     18                           (xmlns="http://www.schemas.thomsonreuters.com/IntBID03")
     19                     )
     20               PATH TABLE      BID_XML_path_table
     21               PATH ID INDEX   BID_XML_pathid_ix
     22               ORDER KEY INDEX BID_XML_orderkey_ix
     23               ASYNC (SYNC ALWAYS) STALE (FALSE)
     24             ');
    CREATE INDEX common.XML_DATA_IDX ON common.BID_XML_TABLE (xml_data)
    *
    ERROR at line 1:
    ORA-29896: Length of PARAMETER string longer than 1000 characters
    
    
    SQL> CREATE INDEX common.BID_XML_DATA_IDX ON common.BID_XML_DATA (xml_data)
      2  INDEXTYPE IS XDB.XMLIndex
    PARAMETERS ('PATHS (INCLUDE (IntegrationBID/Organization/OrgID
      3    4                               IntegrationBID/Organization/OfficerInformation/Officer/ID
      5                               IntegrationBID/Organization/WebLinkInfo
      6                          IntegrationBID/Organization/FilingSpecificInformation/FilingInformation/CompanyID
                                )
      7    8                      NAMESPACE MAPPING
      9                           (xmlns="http://www.schemas.thomsonreuters.com/IntBID03")
                       )
     10   11               PATH TABLE      BID_XML_path_table
     12               PATH ID INDEX   BID_XML_pathid_ix
     13               ORDER KEY INDEX BID_XML_orderkey_ix
     14               ASYNC (SYNC ALWAYS) STALE (FALSE)
     15             ');
    CREATE INDEX common.BID_XML_DATA_IDX ON common.BID_XML_DATA (xml_data)
    *
    ERROR at line 1:
    ORA-29958: fatal error occurred in the execution of ODCIINDEXCREATE routine
    ORA-30955: internal event to enable value index creation
    Could someone help me in creating xmlindex... and also to grant this request.

    -Yasser

    You have 2 options for this make effective and efficient:

    1) move to 11gRx and change the XMLTYPE (based CLOB) column as XML binary XMLType
    (2) in 10 g, the only option to make this work is to change the CLOB, XMLType column base in a relational object XMLType one.

    HTH

    M.

  • error ORA-03113 with XMLTABLE inside the subquery or view

    I get ORA-03113 error if I use a XMLTABLE result within one subquery of another query (if XMLTABLE inline or view). Code below to reproduce that - simplified and now rather meaningless - but produces the same error. Someone at - he seen this error re. XMLTABLE or know bugs in metalink on that? I couldn't find anything. I'll have to use deprecated table (xmlsequence) instead, which does not receive this error.


    -TABLE DROP TEST
    CREATE TABLE TEST (ID number (10), CUST_REF varchar2 (50 char), XMLDATA XMLTYPE);

    INSERT INTO TEST (ID, CUST_REF, XMLDATA) VALUES (1, 'XYZ',
    XMLTYPE ("<?") XML version = "1.0" encoding ="utf-16"? >
    < TESTXML
    xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance".
    xmlns = "urn: ABC - 123:TESTXML" >
    < collection >
    < TRANSACTION_COLLECTION >
    < TRANSACTION >
    < RECORD_ID > 1 < / RECORD_ID >
    < TRANSACTION_ID > 7791786 < / TRANSACTION_ID >
    < AMOUNT > 335 < / AMOUNT >
    < TYPE > I < / TYPE >
    DR < DC > < /DC >
    < / TRANSACTION >
    < / TRANSACTION_COLLECTION >
    < / collections >
    ((< / TESTXML > '));

    COMMIT;

    CREATE VIEW TEST_XMLVIEW
    AS
    SELECT
    ID,
    CUST_REF,
    xmltbl. RECORD_ID,
    xmltbl. TRANSACTION_ID,
    xmltbl. AMOUNT,
    xmltbl. TYPE,
    xmltbl. DC
    OF THE TEST,
    XMLTable (XMLNamespaces (DEFAULT "urn: ABC - 123:TESTXML'"),)
    "/ TESTXML/collections/TRANSACTION_COLLECTION/TRANSACTION" TEST PASSING. XMLDATA
    COLUMNS
    "RECORD_ID" number (10) path "RECORD_ID."
    "TRANSACTION_ID" VARCHAR (200 CHAR) PATH "TRANSACTION_ID"
    "DC' VARCHAR (200 CHAR) PATH"DC. "
    "TYPE' VARCHAR (200 CHAR) PATH"TYPE. "
    ('AMOUNT' NUMBER (38.8) PATH 'QUANTITY')
    AS xmltbl;


    WITH SUM_AMOUNTS (ID, CUST_REF, SUM_1, SUM_2, SUM_3)
    AS
    (SELECT ID, CUST_REF, FLAT AS FLAT AS SUM_2, FLAT + FLAT AS SUM_3, SUM_1)
    OF TEST_XMLVIEW
    GROUP BY ID, CUST_REF)
    Select
    ID,
    CUST_REF,
    SUM_1,
    SUM_2,
    SUM_3
    of SUM_AMOUNTS;


    Version information:
    Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE Production 11.2.0.2.0
    AMT for 64-bit Windows: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production

    Someone at - he seen this error re. XMLTABLE or know bugs in metalink on that? I couldn't find anything.

    Really?

    Go to the directory path and look for the relevant trace or incident file.
    On my system, I can see something like this:

    ORA-07445: exception encountered: core dump [evaopn3()+656] [ACCESS_VIOLATION] [ADDR:0x0] [PC:0x234A5B6] [UNABLE_TO_READ] []
    

    Copy / paste this line into the ORA-00600/ORA-07445 on My Oracle Support search tool and search for your version.
    Read this article:

    * ORA-7445 (evaopn3) [860969.1 ID] *.

    and at the bottom of the page, among the associated bugs known, this one:

    Bug 12724375 : ORA-7445 [evaopn3] XQuery with GROUP BY *.

  • the clause WITH XMLNAMESPACES xmltable: do you go on the internet for xsd?

    Hello

    I have a request of xmltable passing an xmltype variable.

    Something like this:
    select id, name, data
    From XMLTable(XMLNamespaces ('https://www3.somesite.es/bla/bla/bla/thexsd.xsd' as "n1" , 
                                        'https://www3.somesite.es/bla/bla/bla/otherxsd.xsd' as "co") , 
                         '/n1:some/tag' passing l_my_xmltype_var 
    COLUMNS id        NUMBER(20)      PATH '//n1:id' ,
                                 name        VARCHAR2(9)     PATH '//n1:name' ,
                                 data     VARCHAR2(125)   PATH '//co:datatxt') X
    This query is executed in a loop, and we try to improve its performance.
    S/n told me that whenever the query is run, we need to get the two xsd via internet.

    1. is this true?
    2. If it is... Can I keep the local XSD or even inside the database? (I heard something on the registration of the scheme)

    Thank you

    Julius says:
    The actual query has more than 75 columns. Its consumption is spent on java, so I have to assume that this is because of the money the xmltable process analysis.

    You OR do something (horribly) wrong OR should move to a longer version of database great or equal to 10.2.0.3.x

    PLEASE post your version of the database (all figures!)

    Do you mean that, even working with a local xmltable passing a variable xmltype (not a structured xml real chart), save the scheme will do good performance?

    Yep, for example by avoiding calls JAVA... through the registered XML schema validation is optimized if not only because of its kernel code, it's C - code

    I guess I have to:
    1 save the xsd
    2 reference him when I create the xmltype variable (by adding the second parameter to the function of xmltype).

    Fix.

    Then, during the treatment of xmltable, the engine will be smart enough to use the xsd saved info to improve the query performance? Okay, I'm a little skeptical, but will give it a try.

    I will also try to facilitate the processing by specifying the path of the full tree instead of using "/ / tag.

    It will make a difference (providing you're at least on 10.2.0.3.x regarding the use of XMLTABLE, the XQuery engine...)

    As a curiosity, all this quest for optimization of query came when - after a change - the performance of the query went from 5 seconds to 90 seconds. Things went south when I added a * in select it the list instead of referring columns with their names. So it doesn't seem a good idea to use * with a high column number xmltable

    Perhaps, but cannot say. These questions depend on many parameters and environment settings. It could be a connection problem or... or...

    It's one of the reasons why we need the version of database for you give a better answer...

    Published by: Marco Gralike June 8, 2011 11:17

  • Using subselect XMLType, performance issues

    Hello!

    I want to use an XMLType to store various parameters in our software. However, when you use XMLType in a join, as I do, we get huge response times.

    Select takes ~ 4 minutes to run using XMLType in the join.

    I tried to create a temptable (ab_map_order) and use it to join and the select statement runs in 1 second.

    Y at - it another way to use XMLType in the join, or I have to create a temporary table?

    Help much appreciated!
    / Andreas

    -Tables (the name and the columns have been renamed to hide what they do actually)
    CREATE TABLE AB_CONTROL_SETTINGS)
    CONTROL_SETTINGS_ID NUMBER (10) NOT NULL,
    SYS SETTINGS_XML. XMLTYPE,
    SETTINGS_NAME VARCHAR2 (128 CHAR) NOT NULL
    );

    CREATE TABLE AB_COMPANY)
    COMPANY_ID int,
    company_name varchar (255)
    );

    -Insert values
    INSERT INTO AB_COMPANY VALUES (3456, '3456');

    INSERT INTO AB_CONTROL_SETTINGS VALUES (5, XMLType ("< parameters >
    < order >
    < > 234 order_id < / order_id >
    < company > 3456 < / company >
    < / order >
    < order >
    < > 4563 order_id < / order_id >
    < company > 5674 < / company >
    < / order >
    ((< / Parameter > '), 'ORDER');

    -Select with performance problems (no questions in this tiny select however, we have much more data in ab_company) this selection takes about 4 min. That's how I want to do.
    SELECT * from cmp ab_company
    LEFT JOIN (SELECT p.settings_name,
    extractValue (value (order_seq), "/ order/order_id") as order_id,.
    extractValue (value (order_seq), "/ order/company") as a business
    AB_CONTROL_SETTINGS p,
    Table (XMLSequence (p.settings_xml.extract('/settings/order'))) order_seq
    WHERE p.settings_name like ' COMMAND') card ON map.company = cmp.company_name;

    -Create temptable and use it in the join. This selection takes about 1 sec
    create table
    ab_map_order
    as
    (SELECT p.settings_name,
    extractValue (value (order_seq), "/ order/order_id") as order_id,.
    extractValue (value (order_seq), "/ order/company") as a business
    AB_CONTROL_SETTINGS p,
    Table (XMLSequence (p.settings_xml.extract('/settings/order'))) order_seq
    WHERE p.settings_name like 'COMMAND');

    SELECT * from ab_map_order
    LEFT JOIN ab_company ON ab_map_order.company = ab_company.company_name;

    DROP TABLE ab_map_order;

    What version of Oracle you are using.

    Table (xmlsequence... is the old way of doing XML tables, while the most recent method is to use the XMLTABLE construction...

    SELECT *
    from ab_company cmp
         LEFT JOIN (SELECT p.settings_name,
                           o.order_id,
                           o.company
                    FROM AB_CONTROL_SETTINGS p,
                         xmltable('/settings/order'
                                  passing p.settings_xml
                                  columns order_id    number       path '/order/order_id'
                                         ,company     varchar2(30) path '/order/company'
                                 ) o
                    WHERE p.settings_name = 'ORDER') map
         ON map.company=cmp.company_name;
    

    This can help in the exercise (no guarantee that we do not have your test data and do not know your tables or indexes).
    Note: I changed SIMILAR a '=' because there is no generic characters in your string.

  • Display result of function XMLTABLE

    Hi all

    Can any please help me to reach the requirement below.

    I need display output using function XMLTable, as shown below:

    I have a Table like this,

    CREATE TABLE BOMLIST (Cid INT PRIMARY KEY, ELEMENTS XMLTYPE);


    I inserted the next record,

    insert into BOMLIST (Cid, ELEMENTS) values (1, ')
    < item desc = "computer" model = "L1234123" >
    < part desc = "computer" partnum = "5423452345" >
    < desc 'mother' = part partnum = "5423452345" >
    < part desc = partnum "CPU" = "6109486697" >
    < part desc = "registration" partnum = "6109486697" / >
    < / part >
    < part desc = "memory" partnum = "545454232" >
    < part desc = "transistor" partnum = "6109486697" / >
    < / part >
    < / part >

    < part desc = "hard disk" partnum = "6345634563456" >
    < part desc = "spindlemotor" partnum = "191986123" / >
    < / part >
    < part desc = "powersupply" partnum = "098765343" >
    < part desc = "powercord" partnum = "191986123" / >
    < / part >
    < / part >

    < part desc = "monitor" partnum = "898234234" >
    < part desc = "cathoderaytube" partnum = "191986123" / >
    < / part >

    < part desc = "keyboard" partnum = "191986123" >
    < part desc = "keys" partnum = "191986123" / >
    < / part >

    < part desc = "mouse" partnum = "98798734" >
    < part desc = "mouseball" partnum = "98798734" / >
    < / part >
    < / point >
    ')

    I want to output,

    ITEMNAME PARENT PART
    -------------------- -------------------- --------------------
    computer system computer computer system
    computer motherboard computer system
    computer CPU motherboard
    computer registry CPU system
    mother computer system memory card
    transistor computer system memory
    computer hard drive computer system
    system computer spindlemotor hard drive
    computer computer power supply system
    computer system power power cable
    computer monitor computer system system
    system computer cathoderaytube monitor
    system computer keyboard computer system
    computer keyboard keys
    computer system mouse computer system
    computer system mouseball mouse


    I used the query,

    SELECT
    A.ITEMNAME,
    B.PART,
    B.PARENT
    OF BOMLIST.
    XMLTABLE('$doc/item' passing BOMLIST.) ELEMENTS such as "doc".
    COLUMNS
    ITEMNAME varchar (20) PATH '. / @desc',
    XML PATH ELEMENT '.'
    ) AS A,.
    XMLTABLE ('$doc / / part ' in PASSING A.ITEM AS "doc")
    COLUMNS
    PATH varchar (20) PART '. / @desc',
    PATH VARCHAR (20) PARENT '... @desc'
    ) AS B

    Get output,

    ITEMNAME PARENT PART
    -------------------- -------------------- --------------------
    computer system
    computer system motherboard
    computer system CPU
    Computer registry
    computer system memory
    transistor computer system
    computer hard drive system
    system computer spindlemotor
    system computer powersupply
    power cable from the computer system
    Monitor computer system
    system computer cathoderaytube
    computer keyboard
    system computer keycaps
    computer mouse
    system computer mouseball

    that is, Parents column'm NULL values.

    Thank you
    Sunil. N
    SQL> SELECT cast(regexp_substr(column_value,'[^-]+',1,1) as varchar2(30)) col1,
      2    cast(regexp_substr(column_value,'[^-]+',1,2) as varchar2(30)) col2      ,
      3    cast(regexp_substr(column_value,'[^-]+',1,3) as varchar2(30)) col3
      4     FROM bomlist,
      5    xmltable( 'for $str in $doc/item/descendant::* return concat(data($doc/item/@desc),''-'',data
    ($str/@desc),''-'',data($str/../@desc))' passing bomlist.ITEMS AS "doc")
      6
    SQL>
    SQL> /
    
    COL1                           COL2                           COL3
    ------------------------------ ------------------------------ ------------------------------
    computersystem                 computer                       computersystem
    computersystem                 motherboard                    computer
    computersystem                 CPU                            motherboard
    computersystem                 register                       CPU
    computersystem                 memory                         motherboard
    computersystem                 transistor                     memory
    computersystem                 diskdrive                      computer
    computersystem                 spindlemotor                   diskdrive
    computersystem                 powersupply                    computer
    computersystem                 powercord                      powersupply
    computersystem                 monitor                        computersystem
    
    COL1                           COL2                           COL3
    ------------------------------ ------------------------------ ------------------------------
    computersystem                 cathoderaytube                 monitor
    computersystem                 keyboard                       computersystem
    computersystem                 keycaps                        keyboard
    computersystem                 mouse                          computersystem
    computersystem                 mouseball                      mouse
    
    16 rows selected.
    
    SQL> 
    

    The same query, it works for me...
    In xquery... it won't copy the piece in a loop, it will just point it to the same xml file, but for a node to define... And you can cross anyside you like later...

    SQL> select * from v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for HPUX: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    

    Ravi Kumar

  • The result of sort set return per EXTRACT for XMLTYPE

    What is the best way to order the output return by extract?

    My SELECT statement:
    SELECT
    regexp_replace (regexp_replace (Extract (XmlType (t.message_xml), ' / / event '), '< Event >', "),' < / event > ',',')
    OF SUB_XML T

    Output current: EVT_B3_TRAN, EVT_B3_PROD, EVT_B3_FX, EVT_B3_ACC, EVT_B3_PRICE
    Required output: EVT_B3_ACC, EVT_B3_FX, EVT_B3_PROD, EVT_B3_PRICE, EVT_B3_TRAN

    Publish your data in the example so that people can help you.

    You'd better to extract the contents of the XML file by using the XMLTABLE feature rather than an excerpt with regexp_replace string functions.  Process the XML in XML format, not as strings.

    Example:

    SQL > ed
    A written file afiedt.buf

    1 with t as (select xmltype ('))
    2 EVT_B3_TRAN
    3 EVT_B3_PROD
    4 EVT_B3_FX
    5 EVT_B3_ACC
    6 EVT_B3_PRICE
    7
    ") in XML of the double)"
    8  --
    9. end of XML example
    10-
    11. Select listagg (event, ',') the Group (order by rn) as events
    12 years of)
    13. Select x.event
    14, row_number() (x.event order): the nurse
    15 t
    16, xmltable ('/ event/XML ')
    17 passage t.xml
    path of 18 columns event varchar2 (20) '.'
    19                       ) x
    20*      )
    SQL > /.

    EVENTS
    ----------------------------------------------------------------------
    EVT_B3_ACC, EVT_B3_FX, EVT_B3_PRICE, EVT_B3_PROD, EVT_B3_TRAN

  • Retrieve data XML stored in CLOB columns

    Hello

    I have the table below which contains the XML in a CLOB

    CREATE TABLE testxml
      (idcol NUMBER(3), xml_data CLOB
      );
      
    INSERT
    INTO testxml VALUES
      (
        201,
        '
    
    <TRADE>
       <TRADETYPE>SWAP</TRADETYPE>
       <SUBTYPE>CDS</SUBTYPE>
       <TRADEHEADER>
          <ACTION>NEW</ACTION>
          <SOURCEID>ABS-CD</SOURCEID>
          <TRADEID>20595896</TRADEID>
       </TRADEHEADER>
       <TRADELEGS>
          <TRADELEG>
             <PAY_OR_RECEIVE>P</PAY_OR_RECEIVE>
             <FIXED_FLOAT_IND>FLT</FIXED_FLOAT_IND>
             <DAY_COUNT_BASIS>A365F</DAY_COUNT_BASIS>
             <ORIG_PRIMARY_CURRENCY>ZAR</ORIG_PRIMARY_CURRENCY>
             <FIRST_VALUE_DATE>20120511</FIRST_VALUE_DATE>
          </TRADELEG>
          <TRADELEG>
             <PAY_OR_RECEIVE>R</PAY_OR_RECEIVE>
             <FIXED_FLOAT_IND>FIX</FIXED_FLOAT_IND>
             <DAY_COUNT_BASIS>A365F</DAY_COUNT_BASIS>
             <ORIG_PRIMARY_CURRENCY>ZAR</ORIG_PRIMARY_CURRENCY>
             <FIRST_VALUE_DATE>20120511</FIRST_VALUE_DATE>
          </TRADELEG>
       </TRADELEGS>
       <PVS>
          <PV_SOURCE>ABS-CD</PV_SOURCE>
          <PV>
             <NPV>0</NPV>
             <NPV_CCY>ZAR</NPV_CCY>
             <VALUATION_DATE>20130628</VALUATION_DATE>
             <LEG_NUMBER>1</LEG_NUMBER>
          </PV>
          <PV>
             <NPV>2214864.54</NPV>
             <NPV_CCY>ZAR</NPV_CCY>
             <VALUATION_DATE>20130628</VALUATION_DATE>
             <LEG_NUMBER>2</LEG_NUMBER>
          </PV>
       </PVS>
       <CREDIT_DERIVATIVES>
          <CREDIT_DERIVATIVE>
             <NOMINAL>100000000</NOMINAL>
             <MATURITY_DATE>20170620</MATURITY_DATE>
             <BUY_SELL_INDICATOR>SELL</BUY_SELL_INDICATOR>
             <CURRENCY>ZAR</CURRENCY>
          </CREDIT_DERIVATIVE>
          <CREDIT_DERIVATIVE>
             <NOMINAL>100002000</NOMINAL>
             <MATURITY_DATE>20170620</MATURITY_DATE>
             <BUY_SELL_INDICATOR>BUY</BUY_SELL_INDICATOR>
             <CURRENCY>USD</CURRENCY>
          </CREDIT_DERIVATIVE>
       </CREDIT_DERIVATIVES>
    </TRADE>
    
    '
      );
    

    I need the data must be retrieved in the form of columns. I tried the below SQL but it works for a XMLTable i.e. TRADELEGS. But if I try to use another XMLTable for PVS so it is a Cartesian join.

    SELECT id,
      xmltype(xml_data).extract('/TRADE/TRADETYPE/text()').getStringVal()          AS TRADETYPE,
      xmltype(xml_data).extract('/TRADE/SUBTYPE/text()').getStringVal()            AS SUBTYPE,
      xmltype(xml_data).extract('/TRADE/TRADEHEADER/ACTION/text()').getStringVal() AS ACTION,
      x.PAY_OR_RECEIVE,
      x.FIXED_FLOAT_IND
    FROM testxml,
      XMLTable( '/TRADE/TRADELEGS/TRADELEG' passing XMLTYPE(xml_data) 
      columns 
      PAY_OR_RECEIVE VARCHAR2(20) PATH 'PAY_OR_RECEIVE' 
      , FIXED_FLOAT_IND VARCHAR2(20) PATH 'FIXED_FLOAT_IND' ) x;
    

    The query below does not work:

    SELECT id,
      xmltype(xml_data).extract('/TRADE/TRADETYPE/text()').getStringVal()          AS TRADETYPE,
      xmltype(xml_data).extract('/TRADE/SUBTYPE/text()').getStringVal()            AS SUBTYPE,
      xmltype(xml_data).extract('/TRADE/TRADEHEADER/ACTION/text()').getStringVal() AS ACTION,
      tradeleg.PAY_OR_RECEIVE,
      tradeleg.FIXED_FLOAT_IND
      ,xmltype(xml_data).extract('/TRADE/PVS/PV_SOURCE/text()').getStringVal() AS PV_SOURCE
      ,pvs.npv,
      pvs.VALUATION_DATE
    FROM testxml,
      XMLTable( '/TRADE/TRADELEGS/TRADELEG' passing XMLTYPE(xml_data) 
      columns 
      PAY_OR_RECEIVE VARCHAR2(1) PATH 'PAY_OR_RECEIVE' 
    , FIXED_FLOAT_IND VARCHAR2(3) PATH 'FIXED_FLOAT_IND' ) tradeleg
      ,XMLTable( '/TRADE/PVS/PV' passing XMLTYPE(xml_data) 
      columns 
      NPV NUMBER PATH 'NPV' 
    , VALUATION_DATE VARCHAR2(8) PATH 'VALUATION_DATE' ) pvs
    WHERE id = 1;
    

    I need the output to TRADELEGS, PVS and CREDIT_DERIVATIVES.

    Kind regards

    Vikram

    But if I try to use another XMLTable for PVS so it is a Cartesian join.

    Of course, it does. You must use a join condition any.

    What is the correlation of TRADELEGS, PVS and CREDIT_DERIVATIVES?

    I guess you can relate a TICKET to a TRADELEG through the LEG_NUMBER, right? But what about CREDIT_DERIVATIVE PV or TRADELEG?

    I need the output to TRADELEGS, PVS and CREDIT_DERIVATIVES.

    What explains the output should look like.

  • ' Gets an attribute xsi: type with XMLType object relational storage.

    Hello


    How to recover the attribute xsi: type, when you use storage relational XMLType object.

    When you have for example a ProductOrder object type and one object type MoveOrder what a CustomerOrder extensions type how to recover if the CustomerOrder is a kind of MoveOrder or ProductOrder attribute:

    < ns2:customerOrder xsi: type = "ns3:UpcProductOrder" >


    I would use the XMLTable service in combination with the XPath rewrite.

    version of the database 11.2.0.2

    Thanks for the details.

    As I said in my first answer, the prefix xsi is predefined, don't try to redeclare him.

    I know that sounds strange and is in contradiction with what the manual, but it seems to work that way with the storage of GOLD.

    http://docs.Oracle.com/CD/E11882_01/AppDev.112/e23094/xdb_xquery.htm#CBAJBDFA

    You can use these prefixes in XQuery expressions without first declaring in the prologue of the XQuery expression. You can redefine any of them except xml in the prologue.

    If documentation bug or implementation bug? I do not know.

    In any case:

    SQL> BEGIN
      2    DBMS_XMLSCHEMA.registerSchema(
      3      SCHEMAURL => 'test_otn.xsd',
      4      SCHEMADOC => bfilename('TEST_DIR','test_otn.xsd'),
      5      CSID => nls_charset_id('AL32UTF8')
      6    );
      7  END;
      8  /
    
    PL/SQL procedure successfully completed
    
    SQL>
    SQL> insert into cust_order values (xmltype
      2  ('
      3  
      6  a
      7  b
      8  '));
    
    1 row inserted
    
    SQL>
    SQL> SELECT order_id
      2       , order_item
      3       , order_type
      4  FROM cust_order
      5     , XMLTABLE (
      6         XMLNamespaces ('http://bla.com' as "ns1")
      7       , '/ns1:customerOrder'
      8         passing object_value
      9         columns order_id   varchar2(20) path 'ns1:orderId'
     10               , order_item varchar2(20) path 'ns1:orderItem'
     11               , order_type varchar2(30) path '@xsi:type'
     12       ) ;
    
    ORDER_ID             ORDER_ITEM           ORDER_TYPE
    -------------------- -------------------- ------------------------------
    a                    b                    http://bla.com:ProductOrder
     
    

    And if you do want the local name:

    SQL> SELECT order_id
      2       , order_item
      3       , order_type
      4  FROM cust_order
      5     , XMLTABLE (
      6         XMLNamespaces ('http://bla.com' as "ns1")
      7       , '/ns1:customerOrder'
      8         passing object_value
      9         columns order_id   varchar2(20) path 'ns1:orderId'
     10               , order_item varchar2(20) path 'ns1:orderItem'
     11               , order_type varchar2(30) path 'local-name-from-QName(@xsi:type)'
     12       ) ;
    
    ORDER_ID             ORDER_ITEM           ORDER_TYPE
    -------------------- -------------------- ------------------------------
    a                    b                    ProductOrder
     
    

    Hope that helps.

  • With output formatting issues

    DB version: 11.2.0.1.0

    I am facing some formatting issues with my request. The details are the following:


    Here is the part of XML code that I use:
     
            <settlementInformation id="TD1">
                <settlementInstruction>
                    <correspondentInformation>
                        <routingIdsAndExplicitDetails>
                            <routingIds id="INSTRUCTING_PARTY1">
                                <routingId>BICXBICXXXX</routingId>
                                <routingIdScheme>BIC</routingIdScheme>
                            </routingIds>
                            <routingIds id="ORDERING_CUSTOMER1">
                                <routingId>/50F-1-7890123456789012345678901234</routingId>
                                <routingIdScheme>CPI</routingIdScheme>
                            </routingIds>
                            <routingAddress>
                                <streetAddress>
                                    <streetLine>1/a-1-56789012345678901234567890123</streetLine>
                                    <streetLine>2/b-1-56789012345678901234567890123</streetLine>
                                    <streetLine>3/c-1-56789012345678901234567890123</streetLine>
                                    <streetLine>4/d-1-56789012345678901234567890123</streetLine>
                                </streetAddress>
                            </routingAddress>
                            <routingSubAccountNumber>/25A-1-7890123456789012345678901234</routingSubAccountNumber>
                            <routingReferenceText>CHQB</routingReferenceText>
                            <routingReferenceText>OTHR</routingReferenceText>
                            <routingReferenceText>INTC</routingReferenceText>
                        </routingIdsAndExplicitDetails>
                    </correspondentInformation>
                    <intermediaryInformation>
                        <routingIdsAndExplicitDetails>
                            <routingIds>
                                <routingId>BICZBICZYYY</routingId>
                                <routingIdScheme>BIC</routingIdScheme>
                            </routingIds>
                            <routingAccountNumber>A/56A-1-7890123456789012345678901234</routingAccountNumber>
                        </routingIdsAndExplicitDetails>
                        <intermediarySequenceNumber>1</intermediarySequenceNumber>
                    </intermediaryInformation>
                    <beneficiaryBank>
                        <routingIdsAndExplicitDetails>
                            <routingIds>
                                <routingId>RBOSGB2L</routingId>
                                <routingIdScheme>BIC</routingIdScheme>
                            </routingIds>
                            <routingAccountNumber>A/57A-1-7890123456789012345678901234</routingAccountNumber>
                        </routingIdsAndExplicitDetails>
                    </beneficiaryBank>
                    <beneficiary>
                        <routingIdsAndExplicitDetails>
                            <routingIds>
                                <routingId>RBOSGB2RTCM</routingId>
                                <routingIdScheme>BIC</routingIdScheme>
                            </routingIds>
                            <routingAccountNumber>59A-1-7890123456789012345678901234</routingAccountNumber>
                            <routingReferenceText>e-1-5678901234567890123456789012345&#xd;
    f-1-5678901234567890123456789012345&#xd;
    g-1-5678901234567890123456789012345&#xd;
    h-1-5678901234567890123456789012345</routingReferenceText>
                        </routingIdsAndExplicitDetails>
                    </beneficiary>
                    <splitSettlement>
                        <splitSettlementAmount>
                            <currency>USD</currency>
                            <amount>100000000000.0</amount>
                        </splitSettlementAmount>
                        <beneficiary>
                            <routingIdsAndExplicitDetails>
                                <routingIds>
                                    <routingId>RBOSGB2RTCM</routingId>
                                    <routingIdScheme>BIC</routingIdScheme>
                                </routingIds>
                                <routingAccountNumber>59A-1-7890123456789012345678901234</routingAccountNumber>
                                <routingReferenceText>1.3456789012</routingReferenceText>
                            </routingIdsAndExplicitDetails>
                        </beneficiary>
                    </splitSettlement>
                    <splitSettlement>
                        <splitSettlementAmount>
                            <currency>EUR</currency>
                            <amount>100000000000.02</amount>
                        </splitSettlementAmount>
                        <beneficiary>
                            <routingIdsAndExplicitDetails>
                                <routingIds>
                                    <routingId>RBOSGB2RTCM</routingId>
                                    <routingIdScheme>BIC</routingIdScheme>
                                </routingIds>
                                <routingAccountNumber>59A-1-7890123456789012345678901234</routingAccountNumber>
                                <routingReferenceText>1.3456789012</routingReferenceText>
                            </routingIdsAndExplicitDetails>
                        </beneficiary>
                    </splitSettlement>
                    <senderToReceiverInformation>REGULATORY REPORTING: /BENEFRES/GB//77B-1-123456789012345&#xd;
    //77B-1-901234567890123456789012345&#xd;
    //77B-1-901234567890123456789012345</senderToReceiverInformation>
                    <senderToReceiverInformation>DETAILS OF CHARGES: BEN</senderToReceiverInformation>
                </settlementInstruction>
            </settlementInformation>
    Here is a block of the query in the select statement that I use:
     
             ,    XMLTABLE('emml/newTransfer/settlementInformation' PASSING XMLTYPE(gmh.message_xml)) si
             ,    XMLTABLE('settlementInformation' PASSING si.COLUMN_VALUE 
                              COLUMNS settlementInformationId_link1    VARCHAR2(255)  PATH '@id' 
                                    , order_street_address             VARCHAR2(1000) PATH 'settlementInstruction/correspondentInformation/routingIdsAndExplicitDetails/routingAddress/streetAddress'
                           ) mt6
    Now, the result I get is:
     
    1/a-1-567890123456789012345678901232/b-1-567890123456789012345678901233/c-1-567890123456789012345678901234/d-1-56789012345678901234567890123
    whereas what I want is (spaces between the different values of streetLine):
     
    1/a-1-56789012345678901234567890123 2/b-1-56789012345678901234567890123 3/c-1-56789012345678901234567890123 4/d-1-56789012345678901234567890123
    DRM for assistance.

    The string-join has not worked for me

    What you mean? You get an error, or it just do nothing?

    Make sure that you expand the path to the streetLine node:

    string-join(settlementInstruction/correspondentInformation/routingIdsAndExplicitDetails/routingAddress/streetAddress/streetLine, " ")
    
  • XML - ORA-19025: EXTRACTVALUE returns the value of a single node

    Hello

    I'm new to XML DB. Can someone help me with the below XML

    I use the following XML... (I pasted a part only of it coz I need data only up to this article)

    XML
    --------------------

    <? XML version = "1.0" encoding = "UTF-8"? > < SOAP - ENV:Envelope xmlns:SOAP - ENV = "http://schemas.xmlsoap.org/soap/envelope/" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-."
    example"container ="http://www.w3.org/2001/XMLSchema"> < SOAP - ENV:Body >
    < ns:PicklistWS_GetPicklistValues_Output xmlns:ns = "urn: crmondemand/ws/list dropdown /" >
    < ListOfParentPicklistValue xmlns = "urn: / xml/crmondemand/list of choices" >
    < ParentPicklistValue >
    < language > ENU < / language >
    < ParentFieldName > plProduct_Team < / ParentFieldName >
    < ParentDisplayValue > Marketing On Demand < / ParentDisplayValue >
    < ParentCode > Marketing On Demand < / ParentCode >
    < Disabled > N < / disabled >
    < ListOfPicklistValue >
    < PicklistValue >
    Escalation of OCP/SME < code > < code >
    Escalation of OCP/SME < DisplayValue > < / DisplayValue >
    < Disabled > N < / disabled >
    < / PicklistValue >
    < PicklistValue >
    Ask fusion < code > < code >
    Merge request < DisplayValue > < / DisplayValue >
    < Disabled > N < / disabled >
    < / PicklistValue >



    Code
    ---------




    SELECT distinct
    EXTRACTVALUE (value (SR), ' / ParentPicklistValue/ListOfPicklistValue/PicklistValue/Code ','xmlns = "urn: / crmondemand/xml/list of choices"') AS display.
    Return EXTRACTVALUE (value (SR),'/ ParentPicklistValue/ListOfPicklistValue/PicklistValue/DisplayValue ',' xmlns = "urn: / crmondemand/XML/picklist"'),.
    EXTRACTVALUE (value (SR), '/ ParentPicklistValue/ParentDisplayValue','xmlns = "urn: / crmondemand/XML/picklist"') AS parent_display,
    EXTRACTVALUE (value (SR), '/ ParentPicklistValue/ParentCode','xmlns = "urn: / crmondemand/XML/picklist"') AS parent_return
    TABLE (XMLSEQUENCE ((EXCERPT)
    WEB_SERVICE (' <? xml version = "1.0" encoding = "UTF - 8" standalone = "no"? > < envelope soap: xmlns:soap = "http://schemas.xmlsoap.org/soap/envelope/")
    xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" container = "http://www.w3.org/2001/XMLSchema" >
    < soap: Body >
    < PicklistWS_GetPicklistValues_Input xmlns = "urn: crmondemand/ws/list dropdown /" >
    Type < FieldName > < / FieldName >
    Service request < RecordType > < / RecordType >
    < / PicklistWS_GetPicklistValues_Input >
    < / soap: Body >
    "< / envelope soap: >.
    (' document / urn: crmondemand/ws/list dropdown /: ' GetPicklistValues, Id_de_la_session).
    "/: soap envelope / soap: Body / * / * / * ',' xmlns:soap ="(http://schemas.xmlsoap.org/soap/envelope/'))) SR "


    ERROR
    ---------

    ORA-19025: EXTRACTVALUE returns the value of a single node


    UNDERSTANDING
    ---------------------------

    As my Xpath only points until the node - ParentPicklistValue and not the child nodes under it. That's why, when I try to interview the child nodes - / ParentPicklistValue/ListOfPicklistValue/PicklistValue/Code, I get the error mentioned above.

    REQUIREMENT
    -----------------------

    Can someone help me to receive the values of the mother and child values based on xml and query above.

    Hello

    It's a classic ;)

    You need a second XMLSequence who shreds the collection of PicklistValue in relational lines:

    select extractvalue(value(sr2), '/PicklistValue/Code', 'xmlns="urn:/crmondemand/xml/picklist"') AS Display
         , extractvalue(value(sr2), '/PicklistValue/DisplayValue', 'xmlns="urn:/crmondemand/xml/picklist"') AS Return
         , extractvalue(value(sr1), '/ParentPicklistValue/ParentDisplayValue', 'xmlns="urn:/crmondemand/xml/picklist"') AS parent_display
         , extractvalue(value(sr1), '/ParentPicklistValue/ParentCode', 'xmlns="urn:/crmondemand/xml/picklist"') AS parent_return
    from table(
           xmlsequence(
             extract( WEB_SERVICE( ... )
                    , '/soap:Envelope/soap:Body/ns:PicklistWS_GetPicklistValues_Output/ListOfParentPicklistValue/ParentPicklistValue'
                    , 'xmlns="urn:/crmondemand/xml/picklist"
                       xmlns:ns="urn:crmondemand/ws/picklist/"
                       xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' )
           )
         ) sr1
       , table(
           xmlsequence(
             extract( value(sr1)
                    , '/ParentPicklistValue/ListOfPicklistValue/PicklistValue'
                    , 'xmlns="urn:/crmondemand/xml/picklist"' )
           )
         ) sr2
    ;
    

    What is your version of the database BTW?
    10.2 and upward, you can use the XMLTable.

  • Read the column of XMLTYPE with Parent and several child nodes

    Hello

    I have an xmltype column which stores the data in the format below. There is possible that some of the parent node will have several child nodes. I'm not able to extract children nodes. Get the error as a value of type multiset... required singleton...
    I tried the sub query, but it returns only the records from parent with children nodes.

    < CrntRgstns >
    < CrntRgstn empStDt = '2000-08-21' Auth = 'ABCD' regCat = 'BM' u4FlngDt = '2011-05-12' stDt = '2011-11-08' st 'EMPTY' = actvReg = "N" updateTS = "2011-11 - 08T 00: 37:42" >
    < CrntDfcnys / >
    < / CrntRgstn >
    < CrntRgstn empStDt = '2000-08-21' Auth = 'ABCD' regCat = 'BM' u4FlngDt = '2012-01-13' stDt = '2012-01-13' st = 'DÉFICIENT' actvReg = 'Y' updateTS = "2012-01 - 13 T 18: 02:19" >
    < CrntDfcnys >
    < CrntDfcny dfcnyCd = "TEST" exmCd = "M10" createDt = "2012-01-13" / >
    < CrntDfcny dfcnyCd = "TEST" exmCd = "X 40" createDt = "2012-01-13" / >
    < / CrntDfcnys >
    < / CrntRgstn >
    < CrntRgstn empStDt = "2000-08-21" Auth = "XYZ" regCat = "SU" u4FlngDt = '2012-01-13' stDt = '2012-01-13' st = 'DÉFICIENT' actvReg = 'Y' updateTS = "2012-01 - 13 T 18: 02:19" >
    < CrntDfcnys >
    < CrntDfcny dfcnyCd = "TEST" exmCd = "M10" createDt = "2012-01-13" / >
    < CrntDfcny dfcnyCd = "TEST" exmCd = "X 40" createDt = "2012-01-13" / >
    < / CrntDfcnys >
    < / CrntRgstn >
    < / CrntRgstns >

    I tried to use 2 xmltable querys and using the child node of the xmltable 1 as input to xmltable 2. But it returns only the records that has child nodes. But I wanted all the records of CrntRgstn and if no child node CrntDfcnys so that also displays.

    Thank you
    Vinod K

    I tried to use 2 xmltable querys and using the child node of the xmltable 1 as input to xmltable 2. But it returns only the records that has child nodes.

    You're almost there, you just have to do an outer join:

    SQL> select x1.empStDt
      2       , x1.Auth
      3       , x1.regCat
      4       , x2.*
      5  from documents t
      6     , xmltable(
      7         '/CrntRgstns/CrntRgstn'
      8         passing t.xmldoc
      9         columns empStDt date         path '@empStDt'
     10               , Auth    varchar2(30) path '@Auth'
     11               , regCat  varchar2(2)  path '@regCat'
     12               , CrntDfcnys xmltype   path 'CrntDfcnys'
     13       ) (+) x1
     14     , xmltable(
     15         '/CrntDfcnys/CrntDfcny'
     16         passing x1.CrntDfcnys
     17         columns dfcnyCd  varchar2(30) path '@dfcnyCd'
     18               , exmCd    varchar2(3)  path '@exmCd'
     19               , createDt date         path '@createDt'
     20       ) (+) x2
     21  ;
    
    EMPSTDT     AUTH                           REGCAT DFCNYCD                        EXMCD CREATEDT
    ----------- ------------------------------ ------ ------------------------------ ----- -----------
    21/08/2000  ABCD                           BM
    21/08/2000  ABCD                           BM     EXAM                           M10   13/01/2012
    21/08/2000  ABCD                           BM     EXAM                           X40   13/01/2012
    21/08/2000  XYZ                            SU     EXAM                           M10   13/01/2012
    21/08/2000  XYZ                            SU     EXAM                           X40   13/01/2012
     
    

    Note: I have tested the above on 11.2.0.2 and it seems that there is a bug, if we add an outer join on the first XMLTable operator too.
    Normally, the first outer join is not necessary, in order to also test on your version without it.

  • Reading XML clob field

    Hi guys

    I want to read XML file that is stored as a clob in the database table (test_clob) in column (xml_file).

    <?xml version="1.0" encoding="UTF-8"?>
    <!--Sample XML file generated by xmlspy.com)-->
    <mslv-sa:orEvent xmlns:mslv-sa="http://www.metav.com/oss/Sctivation/2003" xmlns:tls="http://www.meolv.com/oss/Sctivation/2003" xmlns:co="http://java.sun.com/products/oss/xml/Common" xmlns:sa="http://java.sun.com/products/oss/xml/Sivation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <co:applicationDN/>
         <co:eventTime>2006-07-17T03:21:13</co:eventTime>
         <sa:currentState>closed.completed</sa:currentState>
         <sa:orderKey>
              <co:applicationDN/>
              <co:type/>
              <sa:primaryKey>SUAUG20_1ADSLCON-268554296-JOB-ISPSERVICE23</sa:primaryKey>
         </sa:orderKey>
         <sa:reason/>
         <mslv-sa:externalSystemId/>
         <mslv-sa:eventId>36</mslv-sa:eventId>
         <mslv-sa:eventStatus>1</mslv-sa:eventStatus>
         <mslv-sa:except>N</mslv-sa:except>
         <mslv-sa:rollbackExcept>N</mslv-sa:rollbackExcept>
         <mslv-sa:services>
              <mslv-sa:item>
                   <mslv-sa:serviceKey>
                        <co:applicationContext>
                             <co:factoryClass/>
                             <co:url/>
                             <co:systemProperties/>
                        </co:applicationContext>
                        <co:applicationDN/>
                        <co:type>ACT_POSTPAID</co:type>
                        <sa:primaryKey>aitorc01_5100719489001</sa:primaryKey>
                        <mslv-sa:serviceSequenceNumber>1</mslv-sa:serviceSequenceNumber>
                   </mslv-sa:serviceKey>
                   <mslv-sa:serviceState>active.completed</mslv-sa:serviceState>
              </mslv-sa:item>
         </mslv-sa:services>
    </mslv-sa:orderCompleteEvent>
    I use the following query just to read data from the file.
    select x.time
    FROM test_clob
            ,XMLTABLE('/mslv-sa:orderCompleteEvent/co:applicationDN/' 
                  PASSING XMLTYPE(test_clob.xml_file)
                  COLUMNS time VARCHAR2(100)PATH '/mslv-sa:orderCompleteEvent/mslv-sa:orderCompleteEvent/co:eventTime')x
    But its giving following error
    21:22:53  LPX-00801: XQuery syntax error at 'EOF'
    21:22:53  1   /mslv-sa:orderCompleteEvent/co:applicationDN/
    Please provide details


    See you soon

    Sexy

    Hi Vanessa,

    I see several issues here.

    -L' example of XML document you gave is not well-formed.
    -Some XPath expressions are false, i.e. they address anything in the document.
    -You must also declare the namespaces that you use in XMLTable.

    Assuming that the root element is actually "mslv - its: orderCompleteEvent", it should be better:

    SELECT x.eventtime
    FROM test_clob t
       , XMLTable(
           XMLNamespaces(
             'http://www.metav.com/oss/Sctivation/2003' as "mslv-sa"
           , 'http://java.sun.com/products/oss/xml/Common' as "co"
           )
         , '/mslv-sa:orderCompleteEvent'
           PASSING XMLTYPE(t.xml_file)
           COLUMNS eventtime timestamp PATH 'co:eventTime'
         ) x
    ;
    
  • Load xml data into an Oracle table

    Hello

    I went through some threads in the forums itself, but for my requirement that nothing comes closer, I write my request. I have a XML like this
    <? XML version = "1.0"? >
    < ACCOUNT_HEADER_ACK >
    < HEADER >
    < STATUS_CODE > 100 < / STATUS_CODE >
    Check < STATUS_REMARKS > < / STATUS_REMARKS >
    < / Header >
    < DETAILS >
    < DETAIL >
    < SEGMENT_NUMBER > 2 < / SEGMENT_NUMBER >
    PR Polytechnic < REMARKS > < / COMMENTS >
    < / DETAILS >
    < DETAIL >
    < SEGMENT_NUMBER > 3 < / SEGMENT_NUMBER >
    < REMARKS > PR Polytechnic administration < / COMMENTS >
    < / DETAILS >
    < DETAIL >
    < SEGMENT_NUMBER > 4 < / SEGMENT_NUMBER >
    < REMARKS > rp Polytechnique finance < / COMMENTS >
    < / DETAILS >
    < DETAIL >
    < SEGMENT_NUMBER > 5 < / SEGMENT_NUMBER >
    < REMARKS > logistics Polytechnique rp < / COMMENTS >
    < / DETAILS >
    < / DETAILS >
    < HEADER >
    < STATUS_CODE > 500 < / STATUS_CODE >
    < STATUS_REMARKS > process exception < / STATUS_REMARKS >
    < / Header >
    < DETAILS >
    < DETAIL >
    < SEGMENT_NUMBER > 20 < / SEGMENT_NUMBER >
    Basic Polytechnique < REMARKS > < / COMMENTS >
    < / DETAILS >
    < DETAIL >
    < SEGMENT_NUMBER > 30 < / SEGMENT_NUMBER >
    < / DETAILS >
    < DETAIL >
    < SEGMENT_NUMBER > 40 < / SEGMENT_NUMBER >
    Finance basic Polytechnique < REMARKS > < / COMMENTS >
    < / DETAILS >
    < DETAIL >
    < SEGMENT_NUMBER > 50 < / SEGMENT_NUMBER >
    Logistics base Polytechnique < REMARKS > < / COMMENTS >
    < / DETAILS >
    < / DETAILS >
    < / ACCOUNT_HEADER_ACK >

    Here is the xml structure of the master structure and child I want to insert data in Oracle tables using the sql * loader initially tried to create a control file, but I don't know how to terminate in the control file, so I created two control files

    load data
    INFILE 'acct.xml' ' str ' < / DETAIL >»»
    TRUNCATE
    in the xxrp_acct_detail table
    TRAILING NULLCOLS
    (
    dummy fill finished by "< DETAIL >."
    SEGMENT_NUMBER surrounded by '< SEGMENT_NUMBER >' and ' < / SEGMENT_NUMBER >, "
    REMARKS framed by 'Of REMARKS <>' and ' < / COMMENTS >.
    )


    load data
    ACCT.XML INFILE' "str" < / header > ' "»
    TRUNCATE
    in the xxrp_acct_header table
    fields terminated by '< HEADER >.
    TRAILING NULLCOLS
    (
    dummy fill finished by "< HEADER >."
    STATUS_CODE framed by '< STATUS_CODE >' and ' < / STATUS_CODE >. "
    STATUS_REMARKS surrounded by '< STATUS_REMARKS >' and ' < / STATUS_REMARKS >.
    )

    I refer to the same xml file in two control files, where with regard to the first control file, I was able to load the files but the second which I suppose as table header not able to load the records of rest. I get the below error.

    Sheet 2: Rejected - error on the XXRP_ACCT_HEADER, column DUMMY table.
    Field in the data file exceeds the maximum length
    Sheet 3: Rejected - error on the XXRP_ACCT_HEADER, column DUMMY table.
    Field in the data file exceeds the maximum length

    In fact if its possible to seggrate a control file so it will be very useful for me. I'm also open for the external table as option. Please help me in this regard.

    Thanks in advance.

    Concerning
    Mr. Nagendra

    Here are two possible solutions:

    (1) reading the headers and separate details using two XMLTables:

    DECLARE
    
     acct_doc xmltype := xmltype( bfilename('TEST_DIR','acct.xml'), nls_charset_id('AL32UTF8') );
    
    BEGIN
    
     insert into xxrp_acct_details (status_code, status_remarks, segment_number, remarks)
     select x1.status_code,
            x1.status_remarks,
            x2.segment_number,
            x2.remarks
     from xmltable(
      '/ACCOUNT_HEADER_ACK/HEADER'
      passing acct_doc
      columns header_no      for ordinality,
              status_code    number        path 'STATUS_CODE',
              status_remarks varchar2(100) path 'STATUS_REMARKS'
     ) x1,
     xmltable(
      '$d/ACCOUNT_HEADER_ACK/DETAILS[$hn]/DETAIL'
      passing acct_doc as "d",
              x1.header_no as "hn"
      columns segment_number number        path 'SEGMENT_NUMBER',
              remarks        varchar2(100) path 'REMARKS'
     ) x2
     ;
    
    END;
    

    All first (alias X 1) retrieves all headers in separate lines. The HEADER_NO generated column is used to keep track of the position of the header into the document.
    Then, we join a second XMLTable (X 2), passing HEADER_NO, so that we can access the corresponding items in DETAIL.

    (2) reading with one XMLTable, but somewhat more complex XQuery:

    DECLARE
    
     acct_doc xmltype := xmltype( bfilename('TEST_DIR','acct.xml'), nls_charset_id('AL32UTF8') );
    
    BEGIN
    
     insert into xxrp_acct_details (status_code, status_remarks, segment_number, remarks)
     select x.*
     from xmltable(
      'for $i in /ACCOUNT_HEADER_ACK/HEADER
       return
        for $j in $i/following-sibling::DETAILS[1]/DETAIL
        return element r {$i, $j}'
      passing acct_doc
      columns status_code    number        path 'HEADER/STATUS_CODE',
              status_remarks varchar2(100) path 'HEADER/STATUS_REMARKS',
              segment_number number        path 'DETAIL/SEGMENT_NUMBER',
              remarks        varchar2(100) path 'DETAIL/REMARKS'
     ) x
     ;
    
    END;
    

    Here, we use an XQuery query to extract the information that we need.
    Basically it's the same logic as above, but with two nested loops which access each header, then each RETAIL location immediately after in the order of the documents.

    Here is the link to the documentation XMLTable and XQuery in Oracle:
    http://download.Oracle.com/docs/CD/B28359_01/AppDev.111/b28369/xdb_xquery.htm#CBAGCBGJ

  • How to use XMLTable on XML encoded

    I have the case of the external web service providing the response is XML, which contains the XML encoded at the breast.

    I would use XMLTable to retrieve the results. I'm familiar with XMLTable, but cannot get to work with mixed coded/non-encoded XML. This returns no data.  If all non-coded, then returns required data. I guess I need to convert somehow, but don't know how to achieve this.

    Code snippet below


    declare
    vResponse XMLType;
    begin
    vResponse:= XMLTYPE(
    '<ValAddrResult>
    <Addresses>
    <item><Address>&lt;AddressLine1&gt;3 Smith Ct&lt;/AddressLine1&gt;</Address></item>
    <item><Address>&lt;AddressLine1&gt;4 Smith Ct&lt;/AddressLine1&gt;</Address></item>
    </Addresses>
    </ValAddrResult>');
    
      for c1 in
      (SELECT x.*
        FROM XMLTABLE ('/ValAddrResult/Addresses/item/Address'
                      passing vResponse
                      COLUMNS AddressLine1 VARCHAR2(500) PATH 'AddressLine1') x)
      loop
        dbms_output.put_line(c1.AddressLine1);
      end loop;
    end;
    
    

    Thank you

    I guess I need to convert somehow, but don't know how to achieve this.

    Exactly.

    You first need to extract the XML string encoded in a VARCHAR2/CLOB column (depending on the expected size).

    Example below uses a CLOB, but you must be at least on 11.2.0.2 full support.

    Then, in a second XMLTABLE, parse the XML string into an XMLType and extract the necessary information:

    SQL> set serveroutput on
    SQL>
    SQL> declare
      2    vResponse XMLType;
      3  begin
      4    vResponse:= XMLTYPE(
      5  '
      6  
      7  
    <AddressLine1>3 Smith Ct</AddressLine1>
    8
    <AddressLine1>4 Smith Ct</AddressLine1>
    9
    10
    '); 11 12 for c1 in ( 13 SELECT x2.* 14 FROM XMLTABLE( 15 '/ValAddrResult/Addresses/item' 16 passing vResponse 17 COLUMNS Address clob PATH 'Address' 18 ) x1 19 , xmltable( 20 '/AddressLine1' 21 passing xmlparse(content x1.address) 22 columns addressline1 varchar2(30) path '.' 23 ) x2 24 ) 25 loop 26 dbms_output.put_line(c1.AddressLine1); 27 end loop; 28 29 end; 30 / 3 Smith Ct 4 Smith Ct PL/SQL procedure successfully completed.

Maybe you are looking for

  • Why Youtube does not display text in Chinese?

    YouTube pages read in Firefox (36.0.1) on my Mini Mac running OSX 10.9.5 show some, but not all, of the text in Chinese. Pages display correctly in Safari and Chrome. I reinstalled and refreshed Firefox with no change. Change view/encoding Western mo

  • Satellite A300-1EH - Webcam driver open fail

    After the disk format (recovery disc HARD T, Vista 32 b) there is no aplication «toshiba face recognition»After installation of Camera Assistant Software, it has that error: Webcam driver open fail. Please restart camera or computer.Camera is off and

  • I can not format my sbRIO 09632 using MAX?

    Hi, I have NEITHER Robotics starter kit 2.0 with sbRIO 09632. At the beginning it works perfectly, now I have the status light will blink twice. The State Max system is: not connected - no software installation. I tried to reinstall the software in t

  • installation of updates for microsoft silverlight

    Why do I get some intalled for microsoft silverlight updates impossible message?

  • my CD / dvd drives have disappeared

    now I can not reload the software or view / do something with the readers. the driver adaptec cd drivers are up-to-date... I can't see readers even less of them use... surely the readers should work / show even if cd / dvd adaptec drivers are out of