Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SAP Sybase SQL Anywhere 16.0 (中文) » SQL Anywhere 服务器 - SQL 用法 » 数据库中的 XML » 使用 SQL/XML 以 XML 形式获取查询结果

 

使用 XMLFOREST 函数

使用 XMLFOREST 可以构建 XML 元素林。对于每个 XMLFOREST 参数,都会生成一个元素。

以下查询会生成一个 <item_description> 元素,其中又包含有 <name>、<color> 和 <price> 元素:

SELECT ID, XMLELEMENT( NAME item_description,
                       XMLFOREST( Name as name,
                                  Color as color,
                                  UnitPrice AS price )
                      ) AS product_info
FROM Products
WHERE ID > 400;

此查询将生成以下结果:

ID product_info
401
<item_description>  <name>Baseball Cap</name>  <color>White</color>  <price>10.00</price> </item_description>
500
<item_description>  <name>Visor</name>  <color>White</color>  <price>7.00</price> </item_description>
501
<item_description>  <name>Visor</name>  <color>Black</color>  <price>7.00</price> </item_description>
... ...
 另请参见