Sei sulla pagina 1di 9

Commands for Querying Oracle Data Dictionary Tables

In order to access DD tables that begin with DBA_, your userid would need to
have been granted the DBA role. Output displayed in the exaples below will !O"
necessarily loo# li#e the output that you will get$your output will vary
depending upon what ob%ects you have de&ined'created in your schea.
(ee the )o&&er et al. textboo# &or a partial list o& DBA_ DD tables *ch+ pg ,-./.
/* use this query to find out what tablespaces have been created for the */
/* oracle database you are accessing. the 6 shown below are the default */
/* tablespaces that are created when, as a part of the installation of po8 */
/* you have oracle create a default database */
/* in practice, you may want to create multiple DAA tablespaces !such as */
/* "A#$%&&'DAA( and point developers, applications, tables, etc. to these */
/* specific tablespaces instead of lumping all tables into )*+$* tablespace */
select tablespace_name from dba_tablespaces;
A,&+*"A-+'.A/+
000000000000000000000000000000
*#*+/
$,*
)*+$*
+/"
%%&*
1.D2
6 rows selected.
/* issue this query to find out what roles have been created for the */
/* oracle db you are accessing. the 3st 34 roles are default roles that */
/* are created when you install oracle5 the 67th role is one 1 created */
select * from dba_roles;
$%&+ "A**8%$
000000000000000000000000000000 0000000
-%..+- .%
$+*%)$-+ .%
D,A .%
+2"'9)&&'DAA,A*+ .%
*+&+-'-AA&%:'$%&+ .%
+2+-)+'-AA&%:'$%&+ .%
D+&++'-AA&%:'$%&+ .%
A;')*+$'$%&+ .%
1/"'9)&&'DAA,A*+ .%
$+-%<+$#'-AA&%:'%8.+$ .%
A;'AD/1.1*$A%$'$%&+ .%
*./"A:+. .%
%+/'/%.1%$ .%
=A<AD+,):"$1< .%
=A<A)*+$"$1< .%
=A<A1D"$1< .%
=A<A*#*"$1< .%
=A<A'AD/1. .%
=A<A'D+"&%# .%
#"1-A&')*+$ .%
1
67 rows selected.
/* use this query to find out what users have been defined for the database, and
what default tablespace they have been assigned. he Default for any non0oracle0
created users is the users tablespace, unless you specify otherwise in the create
user cmd */
/*he first 37 users were created as a part of the oracle installation. 1
created gina'green using the system0manager login. 1 created >imberly, michael,
and gw using the gina'green login. */
select username, default_tablespace from dba_users;
OR
Select username, default_tablespace, created from dba_users
Were created ! "#$%dec%&''(";
)*+$.A/+ D+9A)&'A,&+*"A-+
000000000000000000000000000000 000000000000000000000000000000
*#* *#*+/
*#*+/ %%&*
%)&. *#*+/
D+/% )*+$*
D,*./" *#*+/
*-% )*+$*
"%8 *#*+/
A)$%$A?%$,?).A)@+.1-A+D *#*+/
A)$%$A?=1*?)1&1#? *#*+/
%*+?@"?AD/1. *#*+/
:1.A':$++. )*+$*
A1/,+$&# )*+$*
/1-@A+& )*+$*
:8 )*+$*
3B rows selected.
2
/* use this query to find what usrs !grantees( have been granted what roles */
/* typical'user is a role 1 created */
select grantee, granted_role from dba_role_pri)s *ere grantee not in
+,S-S,, ,S-ST./,0 order by grantee;
:$A.++ :$A.+D'$%&+
000000000000000000000000000000 000000000000000000000000000000
A)$%$A?=1*?)1&1#? $+*%)$-+
D,A D+&++'-AA&%:'$%&+
D,A +2+-)+'-AA&%:'$%&+
D,A +2"'9)&&'DAA,A*+
D,A 1/"'9)&&'DAA,A*+
D,A =A<A'AD/1.
D,A =A<A'D+"&%#
D,A *+&+-'-AA&%:'$%&+
D,*./" -%..+-
D,*./" $+*%)$-+
D,*./" *./"A:+.
D+/% -%..+-
D+/% $+*%)$-+
+2"'9)&&'DAA,A*+ +2+-)+'-AA&%:'$%&+
+2"'9)&&'DAA,A*+ *+&+-'-AA&%:'$%&+
:1.A':$++. A;'AD/1.1*$A%$'$%&+
:1.A':$++. A;')*+$'$%&+
:1.A':$++. -%..+-
:1.A':$++. D,A
:1.A':$++. D+&++'-AA&%:'$%&+
:1.A':$++. +2+-)+'-AA&%:'$%&+
:1.A':$++. +2"'9)&&'DAA,A*+
:1.A':$++. 1/"'9)&&'DAA,A*+
:1.A':$++. =A<AD+,):"$1<
:1.A':$++. =A<A1D"$1<
:1.A':$++. =A<A*#*"$1<
:1.A':$++. =A<A)*+$"$1<
:1.A':$++. =A<A'AD/1.
:1.A':$++. =A<A'D+"&%#
:1.A':$++. %+/'/%.1%$
:1.A':$++. $+-%<+$#'-AA&%:'%8.+$
:1.A':$++. $+*%)$-+
:1.A':$++. *+&+-'-AA&%:'$%&+
:1.A':$++. *./"A:+.
:1.A':$++. #"1-A&')*+$
:8 -%..+-
:8 D,A
1/"'9)&&'DAA,A*+ +2+-)+'-AA&%:'$%&+
1/"'9)&&'DAA,A*+ *+&+-'-AA&%:'$%&+
=A<A*#*"$1< =A<A)*+$"$1<
/1-@A+& #"1-A&')*+$
%+/'/%.1%$ -%..+-
%+/'/%.1%$ *+&+-'-AA&%:'$%&+
%*+?@"?AD/1. =A<A)*+$"$1<
%*+?@"?AD/1. $+*%)$-+
%)&. -%..+-
%)&. $+*%)$-+
"%8 D,A
*-% -%..+-
*-% $+*%)$-+
C7 rows selected.
3
/* there are 6 queries you can use to find out what tables you own. */
/* 9or this one, change )*+$.A/+ to whatever username you use to */
/* log into sqlD5 must use caps */
select o*ner, table_name from all_tables *ere o*ner 1 ,2S.R34/.,;
%8.+$ A,&+'.A/+
000000000000000000000000000000 000000000000000000000000000000
:1.A':$++. -A$$1+$
:1.A':$++. -)*%/+$
:1.A':$++. -)*%/+$'*@1"/+.
:1.A':$++. -)*%/+$'
:1.A':$++. -)*'%$D+$
:1.A':$++. 1.<+.%$#
:1.A':$++. 1.<+.%$#'*@1""1.:
:1.A':$++. 1+/
:1.A':$++. %$D+$'
:1.A':$++. "$%D)-'
37 rows selected.
/* the other query that does the same thing is the following... */
select table_name from user_tables;
A,&+'.A/+
000000000000000000000000000000
-A$$1+$
-)*%/+$
-)*%/+$'*@1"/+.
-)*%/+$'
-)*'%$D+$
1.<+.%$#
1.<+.%$#'*@1""1.:
1+/
%$D+$'
"$%D)-'
37 rows selected.
/* use this query to see tables that were created by others !Eowner(,*/
/* that you have been granted access too, including what privileges */
/* you were granted !Eprivilege( and whether you can grant access to */
/* others !E:$A( */
select * from user_tab_pri)s_recd;
%8.+$ A,&+'.A/+ :$A.%$ "$1<1&+:+ :$A
0000000000000000 00000000000000000000 000000000 00000000000000000 000
*#* 1/A:+*'D1$ *#* $+AD #+*
4
/* the neFt two queries help you find out other obGects you own. */
/* use this query to find out what procedures, functions, and triggers */
/* you have previously created */
select ob5ect_type, ob5ect_name from user_ob5ects
*ere ob5ect_type 1 ,6ROC.D2R., or ob5ect_type 1 ,723CT8O3,
or ob5ect_type 1 ,TR899.R,;
%,=+-'#"+ %,=+-'.A/+
00000000000 00000000000000000000
$1::+$ ADD'%$D+$'"&A-+D'A1$
$1::+$ $+/%<+'%$D+$'"&A-+D',D$
"$%-+D)$+ *@%8-)*
/* this neFt query tells you all obGects you have previously created */
/* including procedures, functions, and triggers as well as tables, */
/* indeFes, constraints, etc. */
select ob5ect_type, ob5ect_name from user_ob5ects;
%,=+-'#"+ %,=+-'.A/+
000000000000000000 00000000000000000000
1.D+2 -)*%/+$'"A
A,&+ -)*%/+$'
1.D+2 %$D+$'DA+'1D2
1.D+2 %$D+$'&1.+'"A
A,&+ %$D+$'&1.+'
1.D+2 %$D+$'"A
A,&+ %$D+$'
1.D+2 "$%D)-'"A
A,&+ "$%D)-'
4 rows selected.
/* to find out what tablespace a userHs table is located inI */
select table_name, tablespace_name from user_tables;
:* to find out storage info for a table; *:
Select tablespace_name, initial_e<tent, ne<t_e<tent, a)g_space, a)g_ro*_len
from user_tables
*ere table_name 1 ,6ROD2CT_T,;
T4=>.S64C._34/. 838T84>_.?T.3T 3.?T_.?T.3T 4@9_S64C. 4@9_ROW_>.3
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%% %%%%%%%%%%% %%%%%%%%%% %%%%%%%%%%%
2S.RS (AA#( B''# C&
5
/* to find out what constraints you have createdI */
select constraint_name, table_name, constraint_type, searc_condition from
user_constraints;
!output below does not include table'name(
-%.*$A1.'.A/+ - *+A$-@'-%.D11%.
00000000000000000000000 0 000000000000000000000000000000000000000000000000000000
*#*'-77CJ68 - K%$D+$'1DK 1* .% .)&&
%$D+$'DA+'-- - %rder'Date LE %'DA+ !M730=A.06777M, MDD0/%.0####M(
%$D+$'"A "
/* in addition to using the D+*-$1,+ command, you can use the */
/* following command to find out what columns are in a table */
select table_name, column_name, data_type, data_lengt, nullable, data_default
from user_tab_columns
*ere table_name 1 DORD.R_T";
A,&+'.A/+ -%&)/.'.A/+ DAA'#"+ DAA'D+9A)&
00000000000000000 0000000000000000000 0000000000000 00000000000000000000000000
%$D+$' %$D+$'1D .)/,+$
%$D+$' %$D+$'DA+ DA+ *#*DA+
%$D+$' -)*%/+$'1D .)/,+$
/* and hereHs what you can use to find out what table and column!s( */
/* an indeF is based on */
select inde<_name, table_name, column_name
from user_ind_columns
*ere inde<_name 1 DSS3_C4>>3O_6E";
/* to find out what privileges you have granted to what users */
select grantee, table_name, pri)ilege from dba_tab_pri)s *ere grantor liFe
,-O2R2S.R34/.G,;
:$A.++ A,&+'.A/+ "$1<1&+:+
000000000000000000000000000000 000000000000000000000000000000 0000000000000000000
"),&1- *)D+. *+&+-
"),&1- "$%9 *+&+-
"),&1- -%)$*+ *+&+-
"),&1- -&A** *+&+-
"),&1- $+:1*$A1%. *+&+-
"),&1- <+.D%$ *+&+-
"),&1- "$%D)- *+&+-
"),&1- -)*%/+$ *+&+-
"),&1- 1.<%1-+ *+&+-
"),&1- "/ *+&+-
"),&1- &1.+ *+&+-
6
I
I
/* to find what system privileges have been granted to roles */
Select pri)ilege, admin_option from role_sys_pri)s *ere role liFe DRO>.34/.G";
/* to find what roles have been granted to roles */
Select granted_role, admin_option from role_role_pri)s *ere role liFe DRO>.34/.
G";
/* to find what table privileges have been granted to roles */
Select * from role_tab_pri)s *ere role liFe DRO>.34/.G";
/* to find what system privileges have been granted to users and roles */
Select * from dba_sys_pri)s *ere grantee liFe D2S.RORRO>.34/.;
/* to determine the code in an eFisting trigger or procedure */
select +2
from )*+$'*%)$-+
where name E M*@%8-)*M
and type E M"$%-+D)$+M
order by &1.+5
select +2
from )*+$'*%)$-+
where name E MADD'%$D+$'"&A-+D'A1$M
and type E M$1::+$M
order by &1.+5
/* to determine whether a tablespace is dictionary or locally managed */
select tablespace_name,e<tent_management from dba_tablespaces
*ere tablespace_name 1 ,HT4=>.S64C.34/.!,;
/* to see what user name is logged on */
So* user;
/* to view how much space is occupied by files within tablespaces */
SELECT file_name, tablespace_name, ROUND(bytes/1024000) MB
FROM dba_data_files
ORDER BY file_name;
/* to view rowidMs of records5 this one gives you the absolute file number */
select customer'id, rowid,
dbms'rowid.rowid'to'absolute'fno !rowid,M:1.A':$++.M,M-)*%/+$'M( A* K91&+K
9$%/ :1.A':$++..-)*%/+$'5
7
-)*%/+$'1D $%81D 91&+
00000000000 000000000000000000 0000000000
3 AAA9F3AADAAAA9mAAA J
6 AAA9F3AADAAAA9mAA, J
J AAA9F3AADAAAA9mAA- J
B AAA9F3AADAAAA9mAAD J
C AAA9F3AADAAAA9mAA+ J
6 AAA9F3AADAAAA9mAA9 J
N AAA9F3AADAAAA9mAA: J
8 AAA9F3AADAAAA9mAA@ J
4 AAA9F3AADAAAA9mAA1 J
37 AAA9F3AADAAAA9mAA= J
33 AAA9F3AADAAAA9mAAA J
36 AAA9F3AADAAAA9mAA& J
3J AAA9F3AADAAAA9mAA/ J
3B AAA9F3AADAAAA9mAA. J
3C AAA9F3AADAAAA9mAA% J
3C rows selected.
/* another !simpler( query that gives Gust the rowid */
select customer'id, rowid
from gina'green.customer't5
/* this query tells you the last time tables you own have been analyOed */
*+&+- A,&+'.A/+, &A*'A.A&#P+D 9$%/ D,A'A,&+* 8@+$+ %8.+$ E M:1.A':$++.M5
/* to see what sequences you have created */
*elect * from user'sequences5
/* to list the physical datafiles that comprise the currently0logged0onto db */
/* you need to >now these in case you ever want to delete a dbQyou canHt drop */
/* a db, so youHll need to physically delete these files and remove the */
/* instance %* service */
select name from v?datafile
union
select name from v?controlfile
union
select member from v?logfile5
/* to find out which oracle instance youHre logged onto */
*+&+- *#*'-%.+2!R)*+$+.<H,HD,'.A/+H( 9$%/ D)A&5
/* to find out which user is logged on in html db */
*+&+- *#*'-%.+2!R)*+$+.<H,H-)$$+.')*+$H( 9$%/ D)A&5
8
/* to find out what columns of a view are updateable */
select * from user'updatable'columns where table'name E M1.<%1-+'<1+8M5
/* to find what type of partitioning is defined for a table */
select table'name, partitioning'type
from user'part'tables
where table'name E M*)D+."M5
/* to find name and partitioned values of partitions */
select table'name, partition'name, high'value
from user'tab'partitions
where table'name E M*)D+."M5
/* to find out what partitions rows are stored in */
select stud'id, classification, dbms'rowid.rowid'to'absolute'fno
!rowid,M*)D+.3M,M*)D+."M( A* K91&+K
9$%/ studentp5
select stud'id, classification, rowid,
dbms'rowid.rowid'relative'fno!rowid( as KfileK,
dbms'rowid.rowid'bloc>'number!rowid( as Kbloc>K
from studentp5
/* to find if a tablespace is autoeFtensible */
*elect autoeFtensible from dba'data'files where tablespace'name E R/#*"A-+H5
/* to find the teFt of your stored proc, trigger, or function */
*elect teFt from user'source where name E M*@1"'DA+M order by line5
9

Potrebbero piacerti anche