Results 1 to 3 of 3

Thread: xmltable

  1. #1
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11

    Unanswered: xmltable

    I am not very familiar with xmltable struggling to get some data
    C:\work>db2 describe table etnic.orders
    Data type Column
    Column name schema Data type name Length Scale Nulls
    ------------------------------- --------- ------------------- ---------- ----- ------
    ID SYSIBM INTEGER 4 0 Yes
    ORDER SYSIBM XML 0 0 Yes

    the sample xml loaded is like
    <?xml version="1.0" encoding="utf-8"?>
    <Root>
    <Customers>
    <Customer CustomerID="GREAL">
    <CompanyName>Great Lakes Food Market</CompanyName>
    <ContactName>Howard Snyder</ContactName>
    <ContactTitle>Marketing Manager</ContactTitle>
    <Phone>(503) 555-7555</Phone>
    <FullAddress>
    <Address>2732 Baker Blvd.</Address>
    <City>Eugene</City>
    <Region>OR</Region>
    <PostalCode>97403</PostalCode>
    <Country>USA</Country>
    </FullAddress>
    </Customer>
    <Customer CustomerID="HUNGC">
    <CompanyName>Hungry Coyote Import Store</CompanyName>
    <ContactName>Yoshi Latimer</ContactName>
    <ContactTitle>Sales Representative</ContactTitle>
    <Phone>(503) 555-6874</Phone>
    <Fax>(503) 555-2376</Fax>
    <FullAddress>

    I want to retrieve companyname and contactname
    tried :
    set current schema = etnic ;
    select id from orders ;
    SELECT
    -- id,
    A.COMPNAME,
    A.CONTNAME
    FROM orders ,
    XMLTABLE('$doc//Customer' PASSING ORDERS.ORDER AS "doc"
    COLUMNS
    COMPNAME VARCHAR(200) PATH './@CompanyName',
    CONTNAME VARCHAR(200) PATH './@ContactName',
    ORDER XML PATH '.'
    )AS A
    ;

    I am getting 4 rows back (correct : companyname occurs 4 times in this xml doc - but the value is always null for both columns
    Any idea what is wrong with this query ?
    Thanks for all help if any....
    db2 10.1.2 on windows
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

  2. #2
    Join Date
    Apr 2008
    Location
    Iasi, Romania
    Posts
    561
    Provided Answers: 2
    @ is for attributes
    it should work with:
    PATH './CompanyName'
    PATH './ContactName'
    Florin Aparaschivei
    DB2 9.7, 10.5 on Windows
    Iasi, Romania

  3. #3
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    thanks Florin - this resolved the problem..
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •