开发者

Can't declare variable in Firebird 2.5, why?

I have a one line query:

DECLARE VARIABLE var_SecondsOfTime INTEGER;

But a开发者_C百科fter running the query I am getting this message:

Engine Error (code = 335544569): Dynamic SQL Error. SQL error code = -104. Token unknown - line 1, column 9. VARIABLE.

SQL Error (code = -104): Invalid token.

I've looked everywhere on the Internet and all examples showing the same declaration style which I am using.

What is wrong?


Firebird 2.5 supports execution of code blocks surrounded by a execute block statement, try this:

set term ^ ;

EXECUTE BLOCK 
AS
   DECLARE VARIABLE var_SecondsOfTime INTEGER;

BEGIN
  SELECT 1 from RDB$DATABASE into var_SecondsOfTime ;
END
^

set term ; ^

I issued the select because I'm pretty sure it is not possible to execute an empty block, try this by yourself removing the select.

Can't declare variable in Firebird 2.5, why?

Edit My original select was invalid for a block, I added the into clause to collect the result. I never used firebird maestro, but it now works perfectly on isql, as shown.


Try this:

set term ^ ;

EXECUTE BLOCK 
AS
   DECLARE VARIABLE var_SecondsOfTime INTEGER;

BEGIN
  SELECT  1 from RDB$DATABASE  into :var_SecondsOfTime ;
END^

set term  ;^

The second set term needs the semi colon before the carat.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜