如何在DB2中运行多个CALL语句

huangapple go评论72阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年2月24日 13:31:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75552923.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定