检查声明的全局临时表在当前会话中是否存在 [英] Check if declared global temporary table exists in current session

查看:140
本文介绍了检查声明的全局临时表在当前会话中是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查当前会话中是否存在DB2中已声明的全局临时表?

How can I check if a declared global temporary table in DB2 exists or not in the current session?

对于我的应用程序,我需要为用户会话创建一次临时表,然后每次执行报告时都可以在其中插入行。因此,当第一次执行报告时,需要从此表中删除所有行,然后用新行重新填充它。

I need to create the temporary table once for a user session and then be able to insert rows in it each time a report is executed in the case of my application. So I need to delete all the rows from this table when a report is executed for more than the first time and then re-populate it with new rows.

现在,创建临时表的方法第二次执行时抛出 42710 SQLSTATE错误

Right now the method creating the temporary table is throwing a 42710 SQLSTATE error the second time it is executed.

此语句对我的实现有用吗: SQLSTATE'42710'的DECARE继续处理程序SET DGTT_FOUND = 1 以及如何我可以在Java( executeUpdate()吗?)

Does this statement work for my implementation: DECLARE CONTINUE HANDLER FOR SQLSTATE '42710' SET DGTT_FOUND=1 and how can I use it in Java (executeUpdate() ?)

推荐答案

根据您不方便指出的DB2版本,可以在声明临时表时使用 WITH REPLACE 选项,即使临时表先前已被使用,该选项也不会成功声明,但也将删除先前插入的行。

Depending on your DB2 version, which you conveniently not indicated, you can use the WITH REPLACE option when declaring the temporary table, which will not only succeed even though the table has been previously declared, but will also take care of deleting the previously inserted rows.

DECLARE GLOBAL TEMPORARY TABLE mytab (
  ...
) NOT LOGGED WITH REPLACE

这篇关于检查声明的全局临时表在当前会话中是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆