【问题标题】:Can't insert into a temporary table无法插入临时表
【发布时间】:2016-07-22 06:04:38
【问题描述】:

我已通过 JDBC 连接到我的新 DB2 数据库,并正在尝试创建和插入一个临时表:

String createTemporaryTable = "declare global temporary table temporary_table (RECORD smallint) ON COMMIT PRESERVE ROWS in TEMPTABLESPACE";
statement.execute(createTemporaryTable);

String insert = "INSERT INTO temporary_table (RECORD) VALUES (1)";

statement.execute(insert);
connection.commit();

这会导致

“DB2 SQL 错误:SQLCODE=-204, SQLSTATE=42704”

创建一个普通表并以这种方式插入不会导致错误。有什么需要配置的吗?

【问题讨论】:

    标签: insert db2 temp-tables


    【解决方案1】:

    您必须将临时表视为在模式会话中。尝试插入:

    String insert = "INSERT INTO session.temporary_table (RECORD) VALUES (1)";
    

    在声明表时会话是隐式的,但为了清楚起见,我通常将其声明为:

    declare global temporary table session.temporary_table (...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-31
      • 2012-08-19
      • 2018-11-20
      • 2011-11-14
      • 1970-01-01
      • 2015-02-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多