community.borland.com
Article #28062: Error: Unexpected end of command
Error: unexpected end of command
The problem
Entering a trigger or stored procedure via IB console,
command line iSQL, or script file gives you the error:
"unexpected end of command".
The source of the problem
You are not setting the parsing terminator to something
other than a semi-colon, which is the default terminator.
The stored procedure language also uses semicolons as
terminators, so when you send a command like this:
CREATE TRIGGER SET_KEY_FIELD_VALUE FOR MY_TABLE
BEFORE INSERT AS
BEGIN
NEW.MY_KEY_FIELD = GEN_ID (MY_GENERATOR, 1);
END
The SQL parser sees this:
CREATE TRIGGER SET_KEY_FIELD_VALUE FOR MY_TABLE
BEFORE INSERT AS
BEGIN
NEW.MY_KEY_FIELD = GEN_ID (MY_GENERATOR, 1)
The parser throws an error, because, as far as it can tell,
the statement has a "BEGIN" but no "END"
The solution
Use SET TERM to set the terminator to something other than
a semi-colon so the parser can correctly determine the whole
statement. This example sets the parsing terminator to a
double pipe, ||.
SET TERM || ;
CREATE TRIGGER SET_KEY_FIELD_VALUE FOR MY_TABLE
BEFORE INSERT AS
BEGIN
NEW.MY_KEY_FIELD = GEN_ID (MY_GENERATOR, 1);
END ||
SET TERM ; ||
Last Modified: 30-NOV-01