我正在尝试使用isql执行以下代码:
IF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = N'SFPTB051_ABERTURARCLH'))
BEGIN
SELECT * FROM SFPTB051_ABERTURARCLH;
END
我正在做的事情:
isql -i sql_scripts/test.sql _input/mygdb.GDB -user SYSADM -pass masterkey
输出:
Statement failed, SQLSTATE = 42000
Dynamic SQL Error
-SQL error code = -104
-Token unknown - line 1, column 1
-IF
At line 1 in file sql_scripts/test.sql
Expected end of statement, encountered EOF
任何想法?
谢谢!
更新---
我正在尝试以下方法:
SET TERM # ;
EXECUTE BLOCK AS
BEGIN
SELECT * FROM SFPTB051_ABERTURARCLH
END#
SET TERM ; #
但它正在回归:
Statement failed, SQLSTATE = 42000
Dynamic SQL Error
-SQL error code = -104
-Token unknown - line 4, column 1
-END
答案 0 :(得分:1)
通常,块语句中的select语句需要返回它们的值。例如,您可以将它们返回到变量或返回值,这几乎是相同的。
此外,块语句中的每个语句都必须以分号(;
)终止。
您的块语句可能如下所示:
SET TERM # ;
EXECUTE BLOCK AS
DECLARE VARIABLE FIELD1 TYPE OF COLUMN SFPTB051_ABERTURARCLH.FIELD1;
/* declare more variables as needed */
BEGIN
FOR
SELECT FIELD1
FROM SFPTB051_ABERTURARCLH
INTO :FIELD1
DO
BEGIN
/* do something with the variables values */
END
END#
SET TERM ; #