英文:
How do I run multiple CALL statements in DB2
问题
以下是翻译好的内容:
我正在尝试使用远程SQL从DB2 (Windows 11.5)运行多个语句。到目前为止,我有:
BEGIN
CALL SYSPROC.SYSTS_CREATE('my_schema', 'my_index', 'my_schema.my_table (column1)', '', 'en_us', ?)
CALL SYSPROC.SYSTS_CREATE('my_schema', 'my_index', 'my_schema.my_table (column2)', '', 'en_us', ?)
END;
这给了我以下错误:
SQL错误 [07004]:EXECUTE语句中的变量数,OPEN语句中的变量数,或参数化游标的OPEN语句中的参数数与所需的值数不相等。 SQLCODE=-313,SQLSTATE=07004,DRIVER=4.26.14
这是从DBeaver运行的,但最终我想将其作为一个命令从C#运行,只是在将其编码到应用程序之前,我想确保语法正确。请注意,每个CALL行在单独运行时都正常工作。
英文:
I'm trying to run multiple statements from DB2 (Windows 11.5) using remote SQL. So far I have:
BEGIN
CALL SYSPROC.SYSTS_CREATE('my_schema', 'my_index', 'my_schema.my_table (column1)', '', 'en_us', ?)
CALL SYSPROC.SYSTS_CREATE('my_schema', 'my_index', 'my_schema.my_table (column2)', '', 'en_us', ?)
END;
This gives me the following error:
SQL Error [07004]: The number of variables in the EXECUTE statement, the number of variables in the OPEN statement, or the number of arguments in an OPEN statement for a parameterized cursor is not equal to the number of values required.. SQLCODE=-313, SQLSTATE=07004, DRIVER=4.26.14
This is running from DBeaver but ultimately I want to run this as one command from C#, just trying to get the syntax right before I code it into the application. Note that each of the CALL lines work fine on their own.
答案1
得分: 2
The SYSTS_CREATE procedure has an output parameter, and you must use the corresponding variable in a compound statement in your application.
BEGIN
DECLARE V_MSG VARCHAR (32672);
CALL SYSPROC.SYSTS_CREATE('my_schema', 'my_index', 'my_schema.my_table (column1)', '', 'en_us', V_MSG);
CALL SYSPROC.SYSTS_CREATE('my_schema', 'my_index', 'my_schema.my_table (column2)', '', 'en_us', V_MSG);
END
To run it in some tool like DBeaver you must change the statement delimiter from the default one (;
) to some other like @
and place it at the end of the statement.
The statement delimiter is changed in DBeaver in the Window -> Preferences -> Editors -> SQL Editor -> SQL Processing -> Delimiters -> Statement Delimiter field.
英文:
The SYSTS_CREATE procedure has an output parameter, and you must use the corresponding variable in a compound statement in your application.
BEGIN
DECLARE V_MSG VARCHAR (32672);
CALL SYSPROC.SYSTS_CREATE('my_schema', 'my_index', 'my_schema.my_table (column1)', '', 'en_us'
, V_MSG);
CALL SYSPROC.SYSTS_CREATE('my_schema', 'my_index', 'my_schema.my_table (column2)', '', 'en_us'
, V_MSG);
END
To run it in some tool like DBeaver you must change the statement delimiter from the default one (;
) to some other like @
and place it at the end of the statement.
The statement delimiter is changed in DBeaver in the Window -> Preferences -> Editors -> SQL Editor -> SQL Processing -> Delimiters -> Statement Delimiter field.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论