oracle 对象查询

来源:互联网 发布:制作桌面日历软件 编辑:程序博客网 时间:2024/06/05 23:44

---dba_  所有   user_  当前

select * from dba_tables where owner = 'AMSDBO';  

select * from user_tables;     

select * from dba_source where owner = 'AMSDBO' and type not in( 'PROCEDURE','FUNCTION');   

select * from user_source;

select * from dba_types where owner = 'AMSDBO';

select * from user_types;

select * from dba_views where owner = 'AMSDBO';

select * from user_views;


0、表空间

      select username,default_tablespace from user_users;

  查看当前用户的角色

   select * from user_role_privs;

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

   select * from user_sys_privs;

   select * from user_tab_privs;

  查看用户下所有的表

   select * from user_tables;

1、用户

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

  select username,default_tablespace from user_users;

  查看当前用户的角色

   select * from user_role_privs;

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

   select * from user_sys_privs;

   select * from user_tab_privs;

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

   select * from session_privs;

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

   select * from dba_sys_privs where grantee='GAME';

2、表

  查看用户下所有的表

   select * from user_tables;

        SELECT * FROM ALL_TABLES;

  查看名称包含log字符的表

   select object_name,object_id from user_objects  where instr(object_name,'LOG')>0;

  查看某表的创建时间

   select object_name,created from user_objects where object_name=upper('&table_name');

  查看某表的大小

   select sum(bytes)/(1024*1024) as "size(M)" from user_segments

  where segment_name=upper('&table_name');

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

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

3、索引

  查看索引个数和类别

  select index_name,index_type,table_name from user_indexes order by table_name;

  查看索引被索引的字段

  select * from user_ind_columns where index_name=upper('&index_name');

  查看索引的大小

  select sum(bytes)/(1024*1024) as "size(M)" from user_segments

  where segment_name=upper('&index_name');

4、序列号

  查看序列号,last_number是当前值

  select * from user_sequences;

5、视图

  查看视图的名称

  select view_name from user_views;

  查看创建视图的select语句

  set view_name,text_length from user_views;

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

  select text from user_views where view_name=upper('&view_name');

6、同义词

  查看同义词的名称

  select * from user_synonyms;

       SELECT * FROM ALL_SYSNONYMS;

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 where object_type='FUNCTION';

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

  查看函数和过程的源代码

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


--◆Oracle查询用户表空间:

        select * from user_all_tables ;

--◆Oracle查询所有函数和储存过程:
        select * from user_source ;

--◆Oracle查询所有用户:
        select * from all_users;
        select * from dba_users ;

--◆Oracle查看当前用户连接:
        select * from v$Session ;

--◆Oracle查看当前用户权限:
select * from session_privs ;

--◆Oracle查看用户表空间使用情况
select a.file_id as "FileNo",
       a.tablespace_name as "Tablespace_name",
       a.bytes as "Bytes",
       a.bytes - sum(nvl(b.bytes, 0)) as "Used",
       sum(nvl(b.bytes, 0)) as "Free",
       sum(nvl(b.bytes, 0)) / a.bytes * 100 as "%free"   
  from dba_data_files a, dba_free_space b
 where a.file_id = b.file_id(+)
 group by a.tablespace_name, a.file_id, a.bytes
 order by a.tablespace_name;


 1、查找表的所有索引(包括索引名,类型,构成列): 

select t.*,i.index_type from user_ind_columns t,user_indexes i where t.index_name = i.index_name and t.table_name = i.table_name and t.table_name = 要查询的表 

2、查找表的主键(包括名称,构成列):   

select cu.* from user_cons_columns cu, user_constraints au where cu.constraint_name = au.constraint_name and au.constraint_type = 'P' and au.table_name = 要查询的表 

3、查找表的唯一性约束(包括名称,构成列): 

select column_name from user_cons_columns cu, user_constraints au where cu.constraint_name = au.constraint_name and au.constraint_type = 'U' and au.table_name = 要查询的表 

4、查找表的外键(包括名称,引用表的表名和对应的键名,下面是分成多步查询): 

select * from user_constraints c where c.constraint_type = 'R' and c.table_name = 要查询的表 

查询外键约束的列名: 

select * from user_cons_columns cl where cl.constraint_name = 外键名称 

查询引用表的键的列名: 

select * from user_cons_columns cl where cl.constraint_name = 外键引用表的键名 

5、查询表的所有列及其属性 

select t.*,c.COMMENTS from user_tab_columns t,user_col_comments c where t.table_name = c.table_name and t.column_name = c.column_name and t.table_name = 要查询的表

6、Oracle中每个用户表的表名和行数

select table_name,num_rows from user_tables;


0 0
原创粉丝点击