Error -104 Unexpected end of command creating a Firebird stored procedure

南笙酒味 提交于 2019-12-24 07:47:04

问题


I want to create a stored procedure in 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

I get this error:

Engine Code : 335544569

Engine Message : Dynamic SQL Error SQL error code = -104 Unexpected end of command - line 18, column 9

The SQL statement:

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'

回答1:


You have to add SET TERM statement before and after the stored procedure. It is used to change the "terminator character". Here's an example:

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 ; ^

Note that default terminator is ^ and also note that you are setting ; as new terminator before and resetting it back to ^ after stored procedure declaration.



来源:https://stackoverflow.com/questions/12586075/error-104-unexpected-end-of-command-creating-a-firebird-stored-procedure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!