Oracleで一時表の一覧を取得したい

表情報を取得するビュー

Oracle では表情報はビュー ALL_TABLES にある。

一時表に関連するカラムは以下

TABLESPACE_NAME

Name of the tablespace containing the table; null for partitioned, temporary, and index-organized tables

TEMPORARY

Can the current session only see data that it place in this object itself?

DURATION

Indicates the duration of a temporary table:
SYS$SESSION: the rows are preserved for the duration of the session
SYS$TRANSACTION: the rows are deleted after COMMIT
Null for a permanent table

出力例

ON COMMIT DELETE ROWS” で作成した一時表の出力例

temporary = 'y'で SELECT すると一覧を取得できる

SELECT table_name, tablespace_name, temporary, duration FROM user_tables WHERE temporary = 'y';

TABLE_NAME TABLESPACE_NAME T DURATION
------------------------------ ------------------------------ - ---------------
TMP_TBL                    Y SYS$TRANSACTION

マニュアルどおり

  • TABLESPACE_NAME はブランク
  • T(TEMPORARY) は ‘Y
  • DURATION SYS$TRANSACTION

となっている。

通常の表の出力例

TABLE_NAME                     TABLESPACE_NAME                T DURATION
------------------------------ ------------------------------ - ---------------
NML_TBL                        USERS                          N

マニュアルどおり

  • TABLESPACE_NAMEUSERS
  • T(TEMPORARY) は ‘N
  • DURATION は ブランク

となっている。

ALL_TABLE/DBA_TABLE/USER_TABLEの違い

これら3つは表示するカラムは同じだけど、表示対象の表が異なる。

マニュアル ALL_TABLES の項の先頭に違いについて説明がある。

  • ALL_TABLES describes the relational tables accessible to the current user
  • DBA_TABLES describes all relational tables in the database.
  • USER_TABLES describes the relational tables owned by the current user. This view does not display the OWNER column.

References

One thought on “Oracleで一時表の一覧を取得したい

  1. 参考になりました~
    ちなみに

    × temporary = ‘y’で SELECT すると一覧を取得できる
    ○ temporary = ‘Y’で ~~

    でした

Leave a comment