Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2012
    Posts
    82

    Unanswered: Querying Data from XML Column

    Hi All.
    I have an XML column in which the data is in the following format
    <root>
    <downstream_systems>
    <system name="XYZ">112</system>
    <system name="ABC">13</system>
    </downstream_systems>
    </root>

    All columns has this XML with different sources and different ID

    What I am trying to do is this..

    Select ID (112) where Syatem Name is "XYZ"

    Any ideas??

    I am stumped

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    This should get you started:

    Code:
    with t(x) as (values xmlparse(document '<root>
    <downstream_systems>
    <system name="XYZ">112</system>
    <system name="ABC">13</system>
    </downstream_systems>
    </root>')) 
    select xmlcast(
        xmlquery('$X/root/downstream_systems/system[@name="XYZ"]') 
        as integer
    ) from t
    ---
    "It does not work" is not a valid problem statement.

  3. #3
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    there are some nice tutorials, samples available in developerswork
    Writing XQuery and SQL/XML queries for DB2 pureXML
    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

  4. #4
    Join Date
    Apr 2008
    Location
    Iasi, Romania
    Posts
    561
    Provided Answers: 2
    I use something like:
    SELECT X.*
    FROM XMLTABLE (...) AS X
    WHERE XMLEXISTS ( ...)
    Florin Aparaschivei
    DB2 9.7, 10.5 on Windows
    Iasi, Romania

Posting Permissions

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