db2命令行处理器中的复合语句 [英] Compound statement in db2 command line processor
问题描述
我正在尝试在DB2命令行处理器中执行以下类型的复合语句
I am trying to execute a compound statement of following type in DB2 command line processor
BEGIN ATOMIC
UPDATE schema.tablename set column1 = xyz where condition = somecondition;
UPDATE schema.tablename2 set column2 = abc where condition = somecondition
END
但是我收到以下错误
BEGIN ATOMIC
UPDATE schema.tablename set column1 = xyz where condition = somecondition
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "END-OF-STATEMENT" was found following "where condition = somecondition".
Expected tokens may include: "<delim_semicolon>". LINE
NUMBER=2. SQLSTATE=42601
UPDATE schema.tablename2 set column2 = abc where condition = somecondition END
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "END" was found following "where condition = somecondition".
Expected tokens may include: "END-OF-STATEMENT". SQLSTATE=42601
SQL0104N An unexpected token "END" was found following "where condition = somecondition". Expected tokens may include: "END-OF-STATEMENT ".
我不确定db2 sql命令行处理器是否支持此功能. 要求是以原子方式而不是存储过程来执行三个查询. 请指导是否还有其他选择.
I am not sure if this is supported in db2 sql command line processor. The requirement is to execute three queries in an atomic fashion but not in a stored procedure. Please guide if there is any other alternative too.
推荐答案
您将需要定义一个非默认的语句终止符,否则命令行处理器无法区分复合语句内的分号和复合语句后的分号.
You will need to define a non-default statement terminator character, otherwise the command line processor cannot distinguish semicolons within a compound statement and the one after the compound statement.
因此,您将以db2 -td@
调用它,将语句终止符设置为"@",您的语句将如下所示:
So, you would invoke it as db2 -td@
, setting the statement terminator to "@", and your statement will look like:
BEGIN ATOMIC
UPDATE schema.tablename set column1 = xyz where condition = somecondition;
UPDATE schema.tablename2 set column2 = abc where condition = somecondition;
END@
这篇关于db2命令行处理器中的复合语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!