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

SQL Anywhere 12.0.0 (中文) » SQL Anywhere 服务器 - SQL 的用法 » 存储过程和触发器 » 使用过程、触发器和批处理 » 从过程返回结果

 

从过程返回结果集

结果集允许过程将多行结果返回到调用环境中。

以下过程会返回已下订单的客户及其所下订单总值的列表。此过程不会列出未下订单的客户。



CREATE PROCEDURE ListCustomerValue()
RESULT ("Company" CHAR(36), "Value" INT)
BEGIN
   SELECT CompanyName,
      CAST( sum(  SalesOrderItems.Quantity *
                  Products.UnitPrice)
                  AS INTEGER ) AS value
   FROM Customers
      INNER JOIN SalesOrders
      INNER JOIN SalesOrderItems
      INNER JOIN Products
   GROUP BY CompanyName
   ORDER BY value DESC;
END;
  • 运行以下语句:

    CALL ListCustomerValue ( );
Company Value
The Hat Company 5016
The Igloo 3564
The Ultimate 3348
North Land Trading 3144
Molly's 2808
... ...
 注意