Can't declare variable in Firebird 2.5, why?

Wodzu picture Wodzu · Feb 2, 2011 · Viewed 9.7k times · Source

I have a one line query:

DECLARE VARIABLE var_SecondsOfTime INTEGER;

But after 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?

Answer

jachguate picture jachguate · Feb 3, 2011

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.

isql running the block

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.