2

我想在 Firebird 中创建一个存储过程:

 CREATE PROCEDURE CalcPvIncome
 ( BeginDate date,
   EndDate   date,
   KwPrice   decimal (2,2) ) 
   
RETURNS ( Total_PV_Production decimal (9,2),
          Total_Income decimal (9,2) )
AS
BEGIN
  
   FOR SELECT SUM(ENERGY/1000), SUM((ENERGY/1000) * :KwPrice) 
       FROM PVPROD 
       WHERE proddate >= :BeginDate AND proddate <= :Enddate 
       INTO :Total_PV_Production , :Total_Income
       DO
       
       BEGIN
        SUSPEND ;
       END
END

我收到此错误:

引擎代码:335544569

引擎消息:动态 SQL 错误 SQL 错误代码 = -104 命令行意外结束 - 第 18 行,第 9 列

SQL 语句:

SELECT 
   SUM(ENERGY/1000) AS Total_PV_Production, 
   sum((ENERGY/1000)*0.55) as Total_Income
FROM 
   PVPROD 
where  
   proddate >= '12.06.2012' and  proddate <= '12.07.2012'
4

1 回答 1

6

您必须SET TERM在存储过程之前和之后添加语句。它用于更改“终止符”。这是一个例子:

SET TERM ^ ;

CREATE PROCEDURE CalcPvIncome
( BeginDate date,
  EndDate   date,
  KwPrice   decimal (2,2) ) 

RETURNS ( Total_PV_Production decimal (9,2),
          Total_Income decimal (9,2) )
AS
BEGIN
  ...
END

SET TERM ; ^

请注意,默认终止符是^并且还请注意,您在;之前设置为新终止符并将其重置回^存储过程声明之后。

于 2012-10-18T05:47:20.670 回答