如何查询Oracle\达梦数据库的所有系统对象、性能视图

在数据库里的数据字典对象和动态性能视图有很多,但是最近学的数据库种类多了以后,有点走火入魔容易记混,在oracle中的中更多,我经常使用的是Tanelpoler的SQL工具包中的d.sql, 或常用的dict和v$fixed_table, 在达梦中dict对应的好像是sysobjects. 发现目前的大模型对国产库回答还不完美,那我给AI准备点语料,简单记录.

Oracle

-- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.

column d_table_name heading TABLE_NAME format a30 
column d_comments heading COMMENTS format a80 word_wrap
break on d_table_name

prompt Show data dictionary views and x$ tables matching the expression "&1"...

select d.table_name d_table_name, d.comments d_comments
	from dict d
	where upper(d.table_name) like upper('%&1%')
union all
select t.table_name d_table_name, 'BASE TABLE' d_comments
	from dba_tables t
	where t.owner = 'SYS'
	and upper(t.table_name) like upper('%&1%')
/
select ft.object_id, ft.name d_table_name, (select fvd.view_name 
			from v$fixed_view_definition fvd 
			where instr(upper(fvd.view_definition),upper(ft.name)) > 0
			and rownum = 1) used_in
	from v$fixed_table ft
	where ft.type in ('TABLE', 'VIEW')
	and replace(upper(ft.name),'V_$','V$') like upper('%&1%')
/

使用

[oracle@db1 ~]$ s

SQL*Plus: Release 23.26.1.0.0 - Production on Mon Jul 13 08:37:09 2026
Version 23.26.1.0.0

Copyright (c) 1982, 2025, Oracle.  All rights reserved.


Connected to:
Oracle AI Database 26ai Enterprise Edition Release 23.26.1.0.0 - Production
Version 23.26.1.0.0


USERNAME             INST_NAME            HOST_NAME                  I# SID   SERIAL#  VERSION    STARTED  SPID       OPID  CPID            SADDR            PADDR
-------------------- -------------------- ------------------------- --- ----- -------- ---------- -------- ---------- ----- --------------- ---------------- ----------------
SYS                  CDB$ROOT-anbob       db1                         1 492   34529    23.26.1.0. 20260304 1254713    36    1254712         00000000B8536EE8 00000000BA6D3A68


SQL> @d advisor
Show data dictionary views and x$ tables matching the expression "advisor"...

TABLE_NAME                     COMMENTS
------------------------------ --------------------------------------------------------------------------------
CDB_ADVISOR_ACTIONS            in all containers
CDB_ADVISOR_COMMANDS           in all containers
CDB_ADVISOR_DEFINITIONS        in all containers
CDB_ADVISOR_DEF_PARAMETERS     in all containers
CDB_ADVISOR_DIR_DEFINITIONS    in all containers
CDB_ADVISOR_DIR_INSTANCES      in all containers
CDB_ADVISOR_DIR_TASK_INST      in all containers
...

达梦

$ cat d.sql
 select name  from sysobjects  where SUBTYPE$  in ('VIEW','STAB') and  upper(name) like upper('%&1%')
 union all
 select name from  V$DYNAMIC_TABLES where upper(name) like upper('%&1%');

使用

SQL> `d history

LINEID     NAME
---------- ------------------------
1          SYSOPENHISTORY
2          VSYSOPENHISTORY
3          V$ACTIVE_SESSION_HISTORY
4          V$WAIT_HISTORY
5          V$CMD_HISTORY
6          V$SQL_HISTORY
7          V$SQL_NODE_HISTORY
8          V$CKPT_HISTORY
9          V$DEADLOCK_HISTORY
...

Leave a Comment