二、用户如何有效地利用数据字典

上一篇 / 下一篇  2009-01-07 22:28:44 / 个人分类:Oracle

  • 文件版本: V1.0
  • 开发商: 本站原创
  • 文件来源: 本地
  • 界面语言: 简体中文
  • 授权方式: 免费
  • 运行平台: Win9X/Win2000/WinXP
二、用户如何有效地利用数据字典51Testing软件测试网0p:B5EG+E+b[/\`
 ORACLE的数据字典是数据库的重要组成部分之一,它随着数据库的产生而产生, 随着数据库的变化而变化,51Testing软件测试网%E9@XvY*p
体现为sys用户下的一些表和视图。数据字典名称是大写的英文字符。51Testing软件测试网P%DQA'piW{6X

[\;YDf'`0数据字典里存有用户信息、用户的权限信息、所有数据对象信息、表的约束条件、统计分析数据库的视图等。
/WqE `5f#Rn Z0我们不能手工修改数据字典里的信息。
9sgN~*^tx0
.`.^/L*\e0  很多时候,一般的ORACLE用户不知道如何有效地利用它。51Testing软件测试网8x*D;HXw+d/}Wk
51Testing软件测试网jSx!z8\
  dictionary   全部数据字典表的名称和解释,它有一个同义词dict
5O7^%@ql1{0dict_column   全部数据字典表里字段名称和解释
9z/\ h(r9`$y IT0
4@0hQa rl!h ]4q"O:T;{0如果我们想查询跟索引有关的数据字典时,可以用下面这条SQL语句:51Testing软件测试网t]N+`w7R]

_X#afX |Q,^#E0SQL>select * from dictionary where instr(comments,'index')>0;51Testing软件测试网sI@.[{dO'{ U3c L(~1g
51Testing软件测试网rM@4r}*["r;?
如果我们想知道user_indexes表各字段名称的详细含义,可以用下面这条SQL语句:51Testing软件测试网y F4S']pxy1OA0Q

$C;Z~I+f$fq#J0SQL>select column_name,comments from dict_columns where table_name='USER_INDEXES';51Testing软件测试网M,@y;m4T"G
51Testing软件测试网H&bY LFF i'g X
依此类推,就可以轻松知道数据字典的详细名称和解释,不用查看ORACLE的其它文档资料了。51Testing软件测试网/J @a0XkG%D^

B6r.\ MM{w0下面按类别列出一些ORACLE用户常用数据字典的查询使用方法。
\kc[c.R?x0s0
XC_9jr(vY01、用户51Testing软件测试网 mjAM S+hg

+ode!Zi$p0查看当前用户的缺省表空间
%y;x\'p/jn;H-VM0SQL>select username,default_tablespace from user_users;
`#].TRv0
hl%ONm0查看当前用户的角色
0V:IK'w3L!X Vw~0SQL>select * from user_role_privs;
AE.^f,D051Testing软件测试网!U F3n q B Im!}
查看当前用户的系统权限和表级权限
m`?i`cv3{%a5~0SQL>select * from user_sys_privs;51Testing软件测试网L E3r;o.R{9?
SQL>select * from user_tab_privs;51Testing软件测试网"n\U6i`5x1f
51Testing软件测试网0wKK(G d~1I ]0E9QXX
2、表
_;q9IGH0
O{9h~` W0查看用户下所有的表51Testing软件测试网} V Z c|I
SQL>select * from user_tables;
(X3Nge$M0
2GHn$wYS(B0sl^0查看名称包含log字符的表
:B,dbjHZ0SQL>select object_name,object_id from user_objects51Testing软件测试网4x-Z@m2| })|y
where instr(object_name,'LOG')>0;51Testing软件测试网8U6y9B }5@ J

)I3Gkxr0查看某表的创建时间51Testing软件测试网F"q gB?U0tD t
SQL>select object_name,created from user_objects where object_name=upper('&table_name');51Testing软件测试网IcX%[!X8w
51Testing软件测试网 E@6s,rLC+B]i
查看某表的大小
0h W)O'T!myJ1E0SQL>select sum(bytes)/(1024*1024) as "size(M)" from user_segments
;u9Y-F%y2`CZ0where segment_name=upper('&table_name');51Testing软件测试网 ReY[:NkUj&N
51Testing软件测试网-g)l/b"Y#m"pZ%?
查看放在ORACLE的内存区里的表
dtOD fJlqc;}0SQL>select table_name,cache from user_tables where instr(cache,'Y')>0;
d?yr ?#t3p$Tm051Testing软件测试网8R/w-SRw a7KP
3、索引51Testing软件测试网jgAl;ZqG
51Testing软件测试网1RMT.dVa
查看索引个数和类别
9qiW4eL,^:QVfbV)i0SQL>select index_name,index_type,table_name from user_indexes order by table_name;
)s0T hU~w9^051Testing软件测试网!?m3M]'nru1Ju;|!t
查看索引被索引的字段51Testing软件测试网3f h7S jK!]3jG
SQL>select * from user_ind_columns where index_name=upper('&index_name');51Testing软件测试网$sbRx!e:t
51Testing软件测试网*Q,D S3g;P%f2tQ5|
查看索引的大小
,{ W8~H}I7j]4L0SQL>select sum(bytes)/(1024*1024) as "size(M)" from user_segments
iqt J V(I!H0where segment_name=upper('&index_name');51Testing软件测试网7l`-d"xQ0J&\)s@

6Q$S!G~2K04、序列号
*X|#p7^4`iD0
@3fs;|p4j0查看序列号,last_number是当前值
;m@BP7bf XK4Y0SQL>select * from user_sequences;51Testing软件测试网0\ l*ajY9au)aM
51Testing软件测试网.e}7O%w!qv
5、视图
*Wu6YK$@c!u)V0
Xbt Dzq0查看视图的名称51Testing软件测试网9rLp.G"_f7H9Y:e @
SQL>select view_name from user_views;
M-sR1mg0
AR8Q9xJ@J`0查看创建视图的select语句51Testing软件测试网J!jdDI4W6l8_
SQL>set view_name,text_length from user_views;51Testing软件测试网0^S}wG]
SQL>set long 2000; 说明:可以根据视图的text_length值设定set long 的大小51Testing软件测试网#F!}Z+xL
SQL>select text from user_views where view_name=upper('&view_name');
8DjYIQnA051Testing软件测试网[?&oKw%L
6、同义词51Testing软件测试网AaW_s+Q
51Testing软件测试网.m!KC7PV)qPG{
查看同义词的名称51Testing软件测试网,L(w0`8H2q0G6I?'b
SQL>select * from user_synonyms;
dk RM]T.q.xO0
kE8J9^3g [&|L^07、约束条件
Ff-}l7r/w0
:syW b.Cc&N2{0查看某表的约束条件51Testing软件测试网!y$E3w a4tM m+Sm
SQL>select constraint_name, constraint_type,search_condition, r_constraint_name51Testing软件测试网(S$Pie Q-Fa!\-r r
from user_constraints where table_name = upper('&table_name');51Testing软件测试网/q(w-@$G0[

8u!y,}9s7_z0SQL>select c.constraint_name,c.constraint_type,cc.column_name51Testing软件测试网,i.}i0a,ZC
from user_constraints c,user_cons_columns cc
R#?8a2\Q"O[(M9}&KC0where c.owner = upper('&table_owner') and c.table_name = upper('&table_name')51Testing软件测试网(i5w-tT]gt"~
and c.owner = cc.owner and c.constraint_name = cc.constraint_name
U#] bS(j])o0order by cc.position;
"N g3wt)}M051Testing软件测试网n/Oj.SU3en ~,l
8、存储函数和过程
vxLG){$E{u051Testing软件测试网I7d uTt1K
查看函数和过程的状态
4C.OFSp"mZ0SQL>select object_name,status from user_objects where object_type='FUNCTION';51Testing软件测试网 }F(AU"Z&kK2W6unc
SQL>select object_name,status from user_objects where object_type='PROCEDURE';
~;X.^W1wI HS0
0_|6@^(B{Xk l w G0查看函数和过程的源代码51Testing软件测试网Q^i,b~&huy
SQL>select text from all_source where ōwner=user and name=upper('&plsql_name');

TAG: Oracle

 

评分:0

我来说两句

Open Toolbar