Oracle 等效于 information_schema.tables
Posted
技术标签:
【中文标题】Oracle 等效于 information_schema.tables【英文标题】:Oracle equivalent of information_schema.tables 【发布时间】:2019-03-07 06:35:00 【问题描述】:当我尝试在 Oracle 中执行以下查询时,出现“表或视图不存在”错误:
SQL查询
SELECT table_type,
table_name
FROM information_schema.tables
WHERE table_rows >= 1;
错误
ORA-00942: 表或视图不存在
我们如何在 Oracle 中查询有关表的元数据?
【问题讨论】:
回复你的cmets,请看这个问题的列数据:-***.com/questions/26790333/… 【参考方案1】:Oracle 确实不提供information_schema
视图,但有自己的数据字典。您可以使用all_tables
创建类似的查询:
SELECT *
FROM all_tables
WHERE num_rows > 1
【讨论】:
请注意,NUM_ROWS 是通过收集表统计信息来填充的。结果的准确性取决于统计数据的新鲜度。 @APC 没错,就像 AFAIK 一样,informatio_schema.tables.table_rows 在任何合理的 RDBMS 中都是如此。 column_name 详细信息未包含在 all_tables 中,从何处获取? @Arun fromall_tab_columns
@Mureinik 谢谢..它的工作。【参考方案2】:
Oracle 中最近的视图是all_tables
。这是每列代表的内容的详细列表。选择最适合您的列以获得所需的详细信息。
ALL_TABLES
COLUMN NAME COMMENTS
----------- ----------
OWNER Owner of the table
TABLE_NAME Name of the table
TABLESPACE_NAME Name of the tablespace containing the table
CLUSTER_NAME Name of the cluster, if any, to which the table
belongs
IOT_NAME Name of the index-only table, if any, to which the
overflow or mapping table entry belongs
STATUS Status of the table will be UNUSABLE if a previous
DROP TABLE operation failed,VALID otherwise
PCT_FREE Minimum percentage of free space in a block
PCT_USED Minimum percentage of used space in a block
INI_TRANS Initial number of transactions
MAX_TRANS Maximum number of transactions
INITIAL_EXTENT Size of the initial extent in bytes
NEXT_EXTENT Size of secondary extents in bytes
MIN_EXTENTS Minimum number of extents allowed in the segment
MAX_EXTENTS Maximum number of extents allowed in the segment
PCT_INCREASE Percentage increase in extent size
FREELISTS Number of process freelists allocated in this
segment
FREELIST_GROUPS Number of freelist groups allocated in this
segment
LOGGING Logging attribute
BACKED_UP Has table been backed up since last modification?
NUM_ROWS The number of rows in the table
BLOCKS The number of used blocks in the table
EMPTY_BLOCKS The number of empty (never used) blocks in the
table
AVG_SPACE The average available free space in the table
CHAIN_CNT The number of chained rows in the table
AVG_ROW_LEN The average row length, including row overhead
AVG_SPACE_FREELIST_BLOC The average freespace of all blocks on a freelist
NUM_FREELIST_BLOCKS The number of blocks on the freelist
DEGREE The number of threads per instance for scanning
the table
INSTANCES The number of instances across which the table is
to be scanned
CACHE Whether the table is to be cached in the buffer
cache
TABLE_LOCK Whether table locking is enabled or disabled
SAMPLE_SIZE The sample size used in analyzing this table
LAST_ANALYZED The date of the most recent time this table was
analyzed
PARTITIONED Is this table partitioned? YES or NO
IOT_TYPE If index-only table, then IOT_TYPE is IOT or
IOT_OVERFLOW or IOT_MAPPING else NULL
TEMPORARY Can the current session only see data that it
place in this object itself?
SECONDARY Is this table object created as part of icreate
for domain indexes?
NESTED Is the table a nested table?
BUFFER_POOL The default buffer pool to be used for table
blocks
FLASH_CACHE The default flash cache hint to be used for table
blocks
CELL_FLASH_CACHE The default cell flash cache hint to be used for
table blocks
ROW_MOVEMENT Whether partitioned row movement is enabled or
disabled
GLOBAL_STATS Are the statistics calculated without merging
underlying partitions?
USER_STATS Were the statistics entered directly by the user?
DURATION If temporary table, then duration is sys$session
or sys$transaction else NULL
SKIP_CORRUPT Whether skip corrupt blocks is enabled or disabled
MONITORING Should we keep track of the amount of
modification?
CLUSTER_OWNER Owner of the cluster, if any, to which the table
belongs
DEPENDENCIES Should we keep track of row level dependencies?
COMPRESSION Whether table compression is enabled or not
COMPRESS_FOR Compress what kind of operations
DROPPED Whether table is dropped and is in Recycle Bin
READ_ONLY Whether table is read only or not
SEGMENT_CREATED Whether the table segment is created or not
RESULT_CACHE The result cache mode annotation for the table
CLUSTERING Whether table has clustering clause or not
ACTIVITY_TRACKING ILM activity tracking mode
DML_TIMESTAMP ILM row modification or creation timestamp
tracking mode
HAS_IDENTITY Whether the table has an identity column
CONTAINER_DATA An indicator of whether the table contains
Container-specific data
INMEMORY Whether in-memory is enabled or not
INMEMORY_PRIORITY User defined priority in which in-memory column
store object is loaded
INMEMORY_DISTRIBUTE How the in-memory columnar store object is
distributed
对于table_rows
,虽然num_rows
是最接近的等价物,但它并不总是为您提供准确的详细信息,除非定期收集表统计信息。在大多数情况下,最好使用select count(*)
。
【讨论】:
谢谢.. 再查询一次,.ALL_TABLES 不包括 COLUMN_NAME 详细信息,从哪里可以获得 COLUMN_NAME 详细信息?以上是关于Oracle 等效于 information_schema.tables的主要内容,如果未能解决你的问题,请参考以下文章
Oracle 等效于 information_schema.tables