oracle数据字典分为静态数据字典和动态数据字典两种。
a、静态数据字典 dba/all/user
b、动态数据字段 v$/gv$
一、显示用户信息。
1、select * from user_users;
2、select sys_context('USERENV', 'CURRENT_USER') usr,
sys_context('USERENV', 'AUTHENTICATION_METHOD') auth_mth,
sys_context('USERENV', 'HOST') host,
sys_context('USERENV', 'INSTANCE_NAME') inst
from dual;
3、select count(*), username from v$session group by username;
4、select a.sid, a.username, b.sql_text
from v$session a, v$sqltext_with_newlines b
where a.sql_id = b.sql_id
order by a.username, a.sid, b.piece;
二、查看您能访问的表。
1、select table_name, tablespace_name from user_tables;
2、select table_name, tablespace_name from all_tables;
3、select grantee, table_name, privilege
from user_tab_privs
where grantee = sys_context('USERENV', 'CURRENT_USER')
order by table_name, privilege;
三、查看一个表的空间使用情况
SELECT a.table_name,
b.tablespace_name,
b.partition_name,
c.file_name,
SUM(b.bytes) / 1024 / 1024 meg_space_used
FROM dba_tables a, dba_extents b, dba_data_files c
WHERE a.owner = 'TSZGYL'
AND a.table_name = 'IC10'
AND a.owner = b.owner
AND a.table_name = b.segment_name
AND b.file_id = c.file_id
GROUP BY a.table_name, b.tablespace_name, b.partition_name, c.file_name
ORDER BY a.table_name, b.tablespace_name;
四、查看索引情况
select a.index_name,
a.column_name,
b.status,
b.index_type,
a.column_position
from user_ind_columns a, user_indexes b
where a.table_name = upper('&table_name')
and a.index_name = b.index_name
order by a.index_name, a.column_position;
五、查看约束情况
select (case constraint_type
when 'P' then
'Primary Key'
when 'R' then
'Foreign Key'
when 'C' then
'Check'
when 'U' then
'Unique'
when 'O' then
'Read Only View'
when 'V' then
'Check view'
when 'H' then
'Hash expression'
when 'F' then
'REF column'
when 'S' then
'Supplemental logging'
end) cons_type,
constraint_name cons_name,
search_condition check_cons,
status
from dba_constraints
where owner like upper('&owner')
and table_name like upper('&table_name')
order by cons_type;
六、显示主键和外键关系
select a.constraint_type cons_type,
a.table_name child_table,
a.constraint_name child_cons,
b.table_name parent_table,
b.constraint_name parent_cons,
b.constraint_type cons_type
from dba_constraints a, dba_constraints b
where a.owner = upper('&owner')
and a.table_name = upper('&table_name')
and a.constraint_type = 'R'
and a.r_owner = b.owner
and a.r_constraint_name = b.constraint_name;
七、显示依赖关系
select '+' || lpad(' ', level + 2) || type || ' ' || owner || '.' || name dep_tree
from dba_dependencies
connect by prior owner = referenced_owner
and prior name = referenced_name
and prior type = referenced_type
start with referenced_owner = upper('tszgyl')
and referenced_name = upper('ac03')
and owner is not null;
八、同义词
select synonym_name, table_owner, table_name, db_link
from user_synonyms
order by 1;
select dbms_metadata.get_ddl('SYNONYM', '名字', '用户名') from dual;
九、查看视图文本
select view_name, text
from dba_views
where owner = upper('&owner')
and view_name like upper('&view_name');
select text
from all_views
where owner = 'INV'
and view_name = 'INV_VIEW';
select text from user_views where view_name = upper('&view_name');
十、查看数据库对象代码
select text
from user_source
where name like upper('&unit_name%')
and type = 'TRIGGER'
order by type, name, line;
select dbms_metadata.get_ddl('TRIGGER', '名字', '用户名') from dual;
十一、查看授予的权限
select username, granted_role from user_role_privs;
select grantee, granted_role
from dba_role_privs
where grantee = upper('&grantee')
order by grantee;
select role from dba_roles;
十二、查看对象权限
select owner, table_name, grantor, privilege from user_tab_privs_recd;
select grantee, table_name, grantor, privilege from user_tab_privs_made;
select grantee, owner, table_name, grantor, privilege
from user_tab_privs
union
select role, owner, table_name, 'ROLE', privilege
from role_tab_privs
order by 2, 3;
十三、查看系统权限
select grantee, privilege, admin_option
from dba_sys_privs
where grantee = UPPER('&grantee')
order by privilege;
select username, privilege, admin_option from user_sys_privs;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7204674/viewspace-622594/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/7204674/viewspace-622594/