Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to identify all global temporary tables

I need to identify which tables in my schema are Global Temporary Tables. Following script returns names of all my tables, but I am not able to identify which of these are GTTs and which are not.

SELECT OBJECT_NAME
FROM ALL_OBJECTS 
WHERE OBJECT_TYPE IN ('TABLE')
AND OWNER='owner_name';

Thank you!

like image 835
Michal Hruška Avatar asked Dec 06 '16 09:12

Michal Hruška


People also ask

How do I find global temporary tables in SQL Server?

Global temp tables are available to all SQL Server sessions or connections (means all the user). These can be created by any SQL Server connection user and these are automatically deleted when all the SQL Server connections have been closed. Global temporary table name is stared with double hash ("##") sign.

How do you identify a global temporary object?

After creation, global temporary tables become visible to any user and any connection. They can be manually dropped with DROP TABLE command. Global temporary tables are automatically dropped when the session that create the table completes and there is no active references to that table.

How are global temporary tables declared?

The CREATETAB privilege to define a declared temporary table in the database that is defined AS WORKFILE, which is the database for declared temporary tables. The USE privilege to use the table spaces in the database that is defined as WORKFILE. All table privileges on the table and authority to drop the table.

Where are global temporary tables stored?

Local temp tables are only accessible from their creation context, such as the connection. Global temp tables are accessible from other connection contexts. Both local and global temp tables reside in the tempdb database.


1 Answers

You can use ALL_TABLES

select table_name
from all_tables
where TEMPORARY = 'Y'
AND OWNER='owner_name';

Temporary column indicates whether the table is temporary (Y) or not (N)

like image 92
Praveen Avatar answered Oct 04 '22 20:10

Praveen