简体   繁体   English

DB2:无法插入或从临时表中选择

[英]DB2: can't insert or select from temporary table

I have tried lots of permutations of DECLARE and CREATE but I can't display any data from my temporary table. 我尝试了很多DECLARECREATE的排列,但无法显示临时表中的任何数据。 Here's the latest iteration: 这是最新的迭代:

DECLARE GLOBAL TEMPORARY TABLE session.temporary_table (ACTNO CHAR); 
INSERT INTO session.temporary_table VALUES ('1'), ('2'); 
SELECT * FROM session.temporary_table; 
SELECT DISTINCT ACTKWD FROM JMILLER.ACT INNER JOIN session.temporary_table ON ACT.ACTNO = session.temporary_table.ACTNO; 
DROP TABLE session.temporary_table;

The first SELECT is to see if there's anything in the temporary_table . 第一个SELECT就是要查看temporary_table是否有任何内容。 Which there doesn't seem to be. 似乎没有。

在此处输入图片说明

Even though when I test the query in this tool it says every line of it completed correctly. 即使当我在此工具中测试查询时,它说它的每一行都正确完成了。

在此处输入图片说明

What am I doing wrong in my sql statements? sql语句中我在做什么错? I was having trouble with permissions earlier but that seems to be fine now and I'm not getting any errors, so it must be in my code. 我之前在权限方面遇到了麻烦,但是现在看来还可以,并且没有出现任何错误,因此它必须在我的代码中。

You did not add the clause ON COMMIT PRESERVE ROWS . 您未添加ON COMMIT PRESERVE ROWS子句。

Also see if you could make things simpler by using CTE (the WITH statement) 另请参阅是否可以通过使用CTE( WITH语句)使事情变得更简单

修改为

 SELECT DISTINCT ACTKWD FROM JMILLER.ACT t0 INNER JOIN session.temporary_table t1 ON t0.ACTNO = t1.ACTNO; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM