简体   繁体   English

"DB2 中有什么方法可以从会话中找到临时表吗?"

[英]Is there any way in DB2 to find temp table from the session?

Is there any way in DB2 to find temp table from the session ? DB2 中是否有任何方法可以从会话中查找临时表?

I have created a temp table pertaining to session我创建了一个与会话有关的临时表

DECLARE GLOBAL TEMPORARY TABLE SESSION.TEMP_TABLE_NAME
(   
        COL_1 VARCHAR(11) NOT NULL,
        COL_2 VARCHAR(10)
) ON COMMIT PRESERVE ROWS;

When I am trying to create query当我尝试创建查询时

select * from sysibm.systables where owner='SESSION' and name='TEMP_TABLE_NAME'

yields 0 rows.产生 0 行。

Am I looking at the incorrect table to find temp tables ?我是否在查看不正确的表以查找临时表?

Thanks !谢谢 !

A declared global temporary table ( DGTT) will not appear in the catalog, this is the design - so you will not find a DGTT in sysibm.systables. 声明的全局临时表(DGTT)将不会出现在目录中,这是设计 - 所以你不会在SYSIBM.SYSTABLES找到DGTT。 A DGTT cannot be used by any other program except the one that declares it - it is specific to that session, hence there's no value to having it in the catalogue. 甲DGTT不能由任何其他程序一起使用,除了声明它的一个 - 它是专用于该会话,因此有在目录有它没有值。

If you are using Db2 for z/OS (v10 or higher), or Db2-LUW, you may need instead, a "CREATED global temporary table" (CGTT) which uses a different syntax create global temporary table ... These are catalogued, but you need relevant permissions to create them. 如果您将Db2用于z / OS(v10或更高版本)或Db2-LUW,则可能需要使用不同语法的“创建的全局临时表”(CGTT) create global temporary table ...这些分类,但您需要相关权限才能创建它们。

See the Db2-LUW documentation . 请参阅Db2-LUW文档 or for Db2 for z/OS here . 此处的 z / OS的Db2。

Look at the SYSIBMADM.ADMINTEMPTABLES administrative view. 查看SYSIBMADM.ADMINTEMPTABLES管理视图。
If you want to see all the DGTTs created in your session, then: 如果要查看在会话中创建的所有DGTT,则:

SELECT TABNAME
FROM SYSIBMADM.ADMINTEMPTABLES
WHERE TEMPTABTYPE='D'
AND APPLICATION_HANDLE=mon_get_application_handle();

如何检查会话中是否存在声明临时表,因为使用选择查询如果它不存在会抛出异常。有没有办法检查没有异常?

"

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

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