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

 

使用 Interactive SQL 查看结果

FOR XML 查询的结果以字符串形式返回。在许多情况下,字符串结果可能相当长。Interactive SQL 可以使用 [在窗口中查看] 选项来显示格式正确的 XML 文档的结构。

通过包含 <?xml?> 标记和任意括起的标记对(例如,<root>...</root>),可以将 FOR XML 查询的结果转换为格式正确的 XML 文档。下面查询说明如何实现这一目的。



SELECT XMLCONCAT( CAST('<?xml version="1.0"?>' AS XML), 
  XMLELEMENT( NAME root, (
    SELECT
          1          AS tag,
          NULL       AS parent,
          EmployeeID AS [employee!1!employeeID],
          NULL       AS [customer!2!customerID],
          NULL       AS [customer!2!region],
          NULL       AS [custname!3!given_name!element],
          NULL       AS [custname!3!surname!element]
    FROM Employees
    UNION DISTINCT 
    SELECT
          2,
          1,
          EmployeeID,
          CustomerID,
          Region,
          NULL,
          NULL
    FROM Employees KEY JOIN SalesOrders
    UNION DISTINCT 
    SELECT
          3,
          2,
          EmployeeID,
          CustomerID,
          NULL,
          Customers.GivenName,
          Customers.SurName
    FROM SalesOrders 
    JOIN Customers 
        ON SalesOrders.CustomerID = Customers.ID 
    JOIN Employees 
        ON SalesOrders.SalesRepresentative = Employees.EmployeeID 
    ORDER BY 3, 4, 1
    FOR XML EXPLICIT
  ) ) 
);

Interactive SQL 列 [截断长度] 值必须足够大,以便能够读取整个列。使用 {工具] » [选项] 菜单或执行如下 Interactive SQL 语句可执行此操作。

SET OPTION truncation_length = 80000;

要查看 XML 文档结果,在 [结果] 窗格中双击列内容,然后选择 [XML 摘要] 选项卡。

 另请参见