【问题标题】:Compound statement in db2 command line processordb2 命令行处理器中的复合语句
【发布时间】:2013-05-31 10:23:58
【问题描述】:

我正在尝试在 DB2 命令行处理器中执行以下类型的复合语句

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 命令行处理器是否支持此功能。 要求是以原子方式而不是在存储过程中执行三个查询。 如果还有其他选择,请指导。

【问题讨论】:

    标签: sql db2 atomic


    【解决方案1】:

    您需要定义一个非默认语句终止符,否则命令行处理器无法区分复合语句中的分号和复合语句之后的分号。

    因此,您可以将其调用为db2 -td@,将语句终止符设置为“@”,您的语句将如下所示:

    BEGIN ATOMIC
     UPDATE schema.tablename set column1 = xyz where condition = somecondition;
     UPDATE schema.tablename2 set column2 = abc where condition = somecondition;
    END@
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-14
      • 1970-01-01
      • 2021-06-23
      • 1970-01-01
      • 2014-11-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多