无法插入临时 table
Can't insert into a temporary table
我已经通过 JDBC 连接到我的新 DB2 数据库,并且正在尝试创建和插入一个临时 table:
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 Error: SQLCODE=-204, SQLSTATE=42704"
创建一个正常的 table 并以这种方式插入不会导致错误。我需要配置什么吗?
您必须在架构会话中引用临时 table。尝试像这样插入:
String insert = "INSERT INTO session.temporary_table (RECORD) VALUES (1)";
session 在声明 table 时是隐含的,但为了清楚起见,我通常将其声明为:
declare global temporary table session.temporary_table (...
我已经通过 JDBC 连接到我的新 DB2 数据库,并且正在尝试创建和插入一个临时 table:
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 Error: SQLCODE=-204, SQLSTATE=42704"
创建一个正常的 table 并以这种方式插入不会导致错误。我需要配置什么吗?
您必须在架构会话中引用临时 table。尝试像这样插入:
String insert = "INSERT INTO session.temporary_table (RECORD) VALUES (1)";
session 在声明 table 时是隐含的,但为了清楚起见,我通常将其声明为:
declare global temporary table session.temporary_table (...