7

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?

Wodzu
  • 6,932
  • 10
  • 65
  • 105
  • Where are you declaring your variable?? stored procedure, or where? from where are you executing your code, isql? other? – jachguate Feb 02 '11 at 23:14
  • @jachguate: I am declaring it in a plain query, which is executed by FirebirdMaestro application. I guess it connects to the DB via isql. As I said it is one line query, nothing more. No stored procedure, nothing. Just this line of code. – Wodzu Feb 03 '11 at 00:01

2 Answers2

5

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.

jachguate
  • 16,976
  • 3
  • 57
  • 98
  • 1
    Thank you for your interest, the error which I have after executing your code is this: Engine Error (code = 335544569): Dynamic SQL Error. SQL error code = -104. Token unknown - line 1, column 1. END. SQL Error (code = -104): Invalid token. Maybe there is something wrong with Firebird Maestro..? – Wodzu Feb 03 '11 at 01:56
  • @Wodzu the block was missing a into clause. I personally never used firebird maestro, so I don't know if it requires a different terminator, I surrounded the block on a couple of set term clauses just in case. – jachguate Feb 03 '11 at 15:19
  • Thanks for your intereest, I'll check your updated answer shortly and will let you know if it worked. – Wodzu Mar 02 '11 at 09:36
  • The second set term needs the semi colon before the carat.. `set term ;^ ` . – bh_earth0 Jul 05 '19 at 07:18
5

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.

bluish
  • 26,356
  • 27
  • 122
  • 180
Ryan
  • 119
  • 3