您的位置:首页 > 数据库 > Oracle

oracle常用数据字典表

2012-10-17 23:32 691 查看
ORACLE的数据字典是数据库的重要组成部分之一,它随着数据库的产生而产生, 随着数据库的变化而变化,体现为sys用户下的一些表和视图。数据字典名称是大写的英文字符。
数据字典里存有用户信息、用户的权限信息、所有数据对象信息、表的约束条件、统计分析数据库的视图等。我们不能手工修改数据字典里的信息。
很多时候,一般的ORACLE用户不知道如何有效地利用它。

dictionary   全部数据字典表的名称和解释,它有一个同义词dict

dict_column   全部数据字典表里字段名称和解释

如果我们想查询跟索引有关的数据字典时,可以用下面这条SQL语句:

SQL>select * from dictionary where instr(comments,'index')>0;

如果我们想知道user_indexes表各字段名称的详细含义,可以用下面这条SQL语句:

SQL>select column_name,comments from dict_columns wheretable_name='USER_INDEXES';

依此类推,就可以轻松知道数据字典的详细名称和解释,不用查看ORACLE的其它文档资料了

tabs 这个其实是用的同义词,真的表叫user_tables.这个顾名思义,当然就是关于表的字典了。所有该用户的表都在这里了。如果你用tab,就只有三列,这个表的信息比较多,其中居然有一列是num-row记录该表有多少条记录。记得以前在一个小服务器上,查一个很大的表的有多少条记录,不管是用count(*)还是用max(rownum),都是巨慢无比,怎么也得查两三分钟,如果当时知道用这个,就简单多了。以前我一直都是用的tab,都不知道从8i开始就是用tabs了。.郁闷.
cols,这个也是同义词,表是user_tab_columns,这个当然就是表的列信息了,比用desc看的信息多。重要的是,如果在程序里想知道一个表有多少列,就可以不用rs倒腾列信息了,列的宽度,是否能为空等,这里都有了。
seq,这个对应的表是user_sequences,序列!
查看当前用户的缺省表空间
SQL>select username,default_tablespace fromuser_users;

查看当前用户的角色
SQL>select * from user_role_privs;
查看当前用户的系统权限和表级权限
SQL>select * from user_sys_privs;
SQL>select * from user_tab_privs;

查看用户下所有的表
SQL>select * from user_tables;
查看用户下所有的表的列属性SQL>select * fromUSER_TAB_COLUMNS where table_name=:table_Name;

显示用户信息(所属表空间)

select default_tablespace,temporary_tablespace

from dba_users where username='GAME';

1、用户

查看当前用户的缺省表空间

SQL>select username,default_tablespace from user_users;

查看当前用户的角色

SQL>select * from user_role_privs;

查看当前用户的系统权限和表级权限

SQL>select * from user_sys_privs;

SQL>select * from user_tab_privs;

显示当前会话所具有的权限

SQL>select * from session_privs;

显示指定用户所具有的系统权限

SQL>select * from dba_sys_privs where grantee='GAME';

显示特权用户

select * from v$pwfile_users;

显示用户信息(所属表空间)

select default_tablespace,temporary_tablespace

from dba_users where username='GAME';

显示用户的PROFILE

select profile from dba_users where username='GAME';

2、表

查看用户下所有的表

SQL>select * from user_tables;

查看名称包含log字符的表

SQL>select object_name,object_id from user_objects

where instr(object_name,'LOG')>0;

查看某表的创建时间

SQL>select object_name,created from user_objects whereobject_name=upper('&table_name');

查看某表的大小

SQL>select sum(bytes)/(1024*1024) as "size(M)" fromuser_segments

where segment_name=upper('&table_name');

查看放在Oracle的内存区里的表

SQL>select table_name,cache from user_tables where instr(cache,'Y')>0;

3、索引

查看索引个数和类别

SQL>select index_name,index_type,table_name from user_indexes orderby table_name;

查看索引被索引的字段

SQL>select * from user_ind_columns whereindex_name=upper('&index_name');

查看索引的大小

SQL>select sum(bytes)/(1024*1024) as "size(M)" fromuser_segments

where segment_name=upper('&index_name');

4、序列号

查看序列号,last_number是当前值

SQL>select * from user_sequences;

5、视图

查看视图的名称

SQL>select view_name from user_views;

查看创建视图的select语句

SQL>set view_name,text_length from user_views;

SQL>set long 2000; 说明:可以根据视图的text_length值设定set long 的大小

SQL>select text from user_views whereview_name=upper('&view_name');

6、同义词

查看同义词的名称

SQL>select * from user_synonyms;

7、约束条件

查看某表的约束条件

SQL>select constraint_name, constraint_type,search_condition,r_constraint_name

from user_constraints where table_name = upper('&table_name');

SQL>select c.constraint_name,c.constraint_type,cc.column_name

from user_constraints c,user_cons_columns cc

where c.owner = upper('&table_owner') and c.table_name =upper('&table_name')

and c.owner = cc.owner and c.constraint_name = cc.constraint_name

order by cc.position;

8、存储函数和过程

查看函数和过程的状态

SQL>select object_name,status from user_objects whereobject_type='FUNCTION';

SQL>select object_name,status from user_objects whereobject_type='PROCEDURE';

查看函数和过程的源代码

SQL>select text from all_source where owner=user andname=upper('&plsql_name');

数据字典dict总是属于oracle用户sys的。

1、用户:

select username from dba_users;

改口令

alter user spgroup identified by spgtest;

2、表空间:

select * from dba_data_files;

select * from dba_tablespaces;//表空间

select tablespace_name,sum(bytes), sum(blocks)

from dba_free_space group by tablespace_name;//空闲表空间

select * from dba_data_files

where tablespace_name=’rbs’;//表空间对应的数据文件

select * from dba_segments

where tablespace_name=’indexs’;

3、数据库对象:

select * from dba_objects;

cluster、database link、function、index、library、package、package body、

procedure、sequence、synonym、table、trigger、type、undefined、view。

4、表:

select * from dba_tables;

analyze my_table compute statistics;->dba_tables后6列

select extent_id,bytes from dba_extents

where segment_name=’customers’ and segment_type=’table’

order by extent_id;//表使用的extent的信息。segment_type=’rollback’查看回滚段的空间分配信息

列信息:

select distinct table_name

from user_tab_columns

where column_name=’so_type_id’;

5、索引:

select * from dba_indexes;//索引,包括主键索引

select * from dba_ind_columns;//索引列

select i.index_name,i.uniqueness,c.column_name

from user_indexes i,user_ind_columns c

where i.index_name=c.index_name

and i.table_name =’acc_nbr’;//联接使用

6、序列:

select * from dba_sequences;

7、视图:

select * from dba_views;

select * from all_views;

text 可用于查询视图生成的脚本

8、聚簇:

select * from dba_clusters;

9、快照:

select * from dba_snapshots;

快照、分区应存在相应的表空间。

10、同义词:

select * from dba_synonyms

where table_owner=’spgroup’;

//if owner is public,then the synonyms is a publicsynonym.

if owner is one of users,then the synonyms is aprivate synonym.

11、数据库链:

select * from dba_db_links;

在spbase下建数据库链

create database link dbl_spnew

connect to spnew identified by spnew using ’jhhx’;

insert into acc_nbr@dbl_spnew 资

V$view
++++++++++++++++++
1.v$fixed_table
所有可用的动态性能视图(DICT)
----------------------------------------------------
2.v$instance
用来获取当前实例的详细信息
---------------------------------------------------
3.v$sga/v$sgainfo
获取当前实例中SGA的详细信息
---------------------------------------------------
4.v$session
用来查询当前会话信息
kill session
altersystem kill session 'sid,serial#'
--------------------------------------------------
5.v$bgpprocess
用来查询后台进程的详细信息
------------------------------------------------
6.v$database
获取当前数据库的详细信息
------------------------------------------------
======================================================================
DICT
+++++++++++++++++++++
1.DICT
返回当前用户能够访问的所有数据字典视图和动态视图
------------------------------------------------------------------------------
2.dict_columns
用来显示数据字典视图中每个列的描述
------------------------------------------------------------------------------
3.dba_users
返回数据库中所有用户的用户名及用户号
4.dba_types
存放Oracle支持的数据类型
----------------------------------------------------------------------------
永久表空间及数据文件等信息
++++++++++++++++++++++++++
1.dba_tablespaces
查询表空间信息
--------------------------------------------------------
2.dba_data_files
查询数据文件信息
-------------------------------------------------------
3.v$datafile
用来查询当前数据库所有数据文件信息
-------------------------------------------------------
4.dba_ts_quotas
配额信息
-------------------------------------------------------
5.dba_free_space
FREESPACE
有关临时表空间的信息:
+++++++++++++++++++++
1.dba_temp_files
查询临时表空间对应数据文件信息
------------------------------------------------------
2.v$tempfile
------------------------------------------------------
参数文件,控制文件,日志文件
+++++++++++++++++++++++++++++
1.v$parameter
用来获取数据库初始化参数详细信息
----------------------------------------------------------------------
2.v$controlfile
用来查询当前数据库所有控制文件信息
---------------------------------------------------------------------
3.v$logfile
查询当前数据库所有重作日志文件信息
V$log
日志信息
--------------------------------------------------------------------
获取和权限有关的信息:
+++++++++++++++++++++
1.dba_sys_privs
列出授予用户和角色的系统权限
------------------------------------------------------------------
2.session_privs
列出用户当前可用的权限
3.dba_tab_privs
列出对于数据库中所有对象的所有授权
-----------------------------------------------------------------
4.dba_col_privs
描述数据库中的所有对象授权
----------------------------------------------------------------
获取和角色有关的信息:
++++++++++++++++++++++
1.dba_roles
数据库中的所有角色
---------------------------------------------------------------
2.dba_roles_privs
授予用户和角色的角色
---------------------------------------------------------------
3.dba_sys_privs
授予用户和角色的系统权限
---------------------------------------------------------------
4.role_rol_privs
授予角色的角色
---------------------------------------------------------------
5.role_sys_privs
授予角色的系统权限
---------------------------------------------------------------
6.role_tab_privs
授予角色的对象权限
---------------------------------------------------------------
7.session_roles
用户当前启用的角色
---------------------------------------------------------------
获取和用户资源配置有关的信息:
+++++++++++++++++++++++++
1.dba_users
--------------------------------------
2.dba_profiles
--------------------------------------
获取和同义词相关的DICT:
++++++++++++++++++++++++++
1.user_synonym
------------------------------------
2.dba_synonym
------------------------------------
和闪回有关的VIEW
++++++++++++++++++++++++++
1.v$database
--------------------------------------
2.v$flashback_database_log
--------------------------------------
3.v$flashback_database_stat
--------------------------------------
======================================================================

USERS_DICT

======================================================================
和表相关的DICT:
++++++++++++++++
1.user_objects
-----------------------------------------
2.user_tables
-----------------------------------------
3.user_tab_comments
获取表注释
----------------------------------------
4.user_col_comments
获取列注释
---------------------------------------
和视图相关的DICT:
+++++++++++++++++
1.user_objects:
获取视图的名称
------------------------------------------------------------------------------
2.user_views:
获取视图对应的查询语句
----------------------------------------------------------------------------
3.user_update_columns:
获取视图是否可以在特定的列上执行DML操作
----------------------------------------------------------------------------
和索引相关的DICT:
+++++++++++++++++
1.user_index [IND]
获取索引信息
-------------------------------------------------
2.user_ind_columns
获取索引详细信息
-------------------------------------------------
和序列相关的DICT:
++++++++++++++++++++++++++
1.user_sequences [SEQ]
获取序列的详细信息
--------------------------------------------------
其它常用DICT
1.查询用户创建的约束条件
user_constraints
--------------------------------------------------
2.查询用户创建的函数和过程
user_procedures
-------------------------------------------------
3.查询用户存储过程和函数的内容(源码)
user_source
-------------------------------------------------
和同义词相关的DICT:
++++++++++++++++++
1.user_synonym
-------------------------------------------------------
对象统计数据:
++++++++++++++++++
1、 表的统计数据
dba_tables
2、 索引的统计数据
dba_indexes
3、 表监控得到的统计数据
USER_TAB_MODIFICATIONS
调度任务:
1、dba_scheduler_jobs
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: