Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't declare variable in Firebird 2.5, why?

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?

like image 340
Wodzu Avatar asked Feb 02 '11 22:02

Wodzu


2 Answers

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.

like image 57
jachguate Avatar answered Sep 17 '22 18:09

jachguate


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.

like image 30
Ryan Avatar answered Sep 20 '22 18:09

Ryan