Search
Tuesday, May 13, 2008 ..:: Forum ::.. Register  Login
 
  Forum  Templates  SQL Usage  Generating XML from an Oracle SQL statement
Disabled Previous
 
Next Disabled
New Post 5/7/2008 4:28 PM
  hanebch
2 posts
No Ranking


Generating XML from an Oracle SQL statement 

For those interested in generating an xml document from Oracle that can then be used by a Windward template, here is a simple example.  listed below is the syntax to created a sorted xml document two levels deep.  You can create further levels of nested tags via more sub-selects.  Note that the sort order is established as part of the XMLAGG function, not by the usual method of including the "order by" clause after the "where" clause in the SQL.  Extend as appropriate.  There is also a decent beginers guide at http://www.oracle-base.com/articles/9i/SQLXML9i.php

/* begin XML document */
select xmlelement("MyReportDataRoot", xmlelement("FlagsLvl1",
/* First Level Customer flags root   */
      (select xmlagg(xmlelement("CustFlag",XMLATTRIBUTEs(cf.flag_id),xmlforest(
           cf.flag_id,
           cf.flag_value
       ))order by cf.flag_id desc)
       from packinglist pl
       join customerflag cf on cf.company_code = pl.company_code
                      and cf.customer_number = pl.customer_number
                      and cf.category_id = '11'
       where pl.company_code = &Company
          and pl.site_code = &Site
          and pl.packing_list_number = &PackingList
       ))
/* end of XML document */
).getCLOBVal() MyReportDataXML
from dual;

 
Disabled Previous
 
Next Disabled
  Forum  Templates  SQL Usage  Generating XML from an Oracle SQL statement
 Old Windward Forums Minimize


 Print   
Membership Membership:
Latest New User Latest: mgetz
New Today New Today: 1
New Yesterday New Yesterday: 1
User Count Overall: 38

People Online People Online:
Visitors Visitors: 9
Members Members: 0
Total Total: 9

Online Now Online Now:
All contents copyright (c) 2002 - 2008 by Windward Studios, Inc. All Rights Reserved.   Terms Of Use  Privacy Statement