C/C++教程

查看Oracle当前用户下的(表,视图,同义词,索引等...)

本文主要是介绍查看Oracle当前用户下的(表,视图,同义词,索引等...),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 copy自:查看Oracle当前用户下的(表,视图,同义词,索引等...)

表空间
– 查看当前用户表空间

select username,default_tablespace from user_users;
select default_tablespace from dba_users where username='用户名'

– 查询表空间下的用户

select distinct s.owner from dba_segments s where s.tablespace_name ='表空间名';

– 查看当前用户下所有表空间的使用情况:

SELECT a.tablespace_name "表空间名",
total / (1024 * 1024) "表空间大小(M)",
free / (1024 * 1024) "表空间剩余大小(M)",
(total - free) / (1024 * 1024) "表空间使用大小(M)",
round((total - free) / total, 4) * 100 "使用率 %"
FROM (SELECT tablespace_name, SUM(bytes) free
FROM dba_free_space
GROUP BY tablespace_name) a,
(SELECT tablespace_name, SUM(bytes) total
FROM dba_data_files
GROUP BY tablespace_name) b
WHERE a.tablespace_name = b.tablespace_name;
SELECT UPPER(F.TABLESPACE_NAME) "表空间名",
       D.TOT_GROOTTE_MB "表空间大小(M)",
       D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空间(M)",
       TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100,
                     2),
               '990.99') || '%' "使用比",
       F.TOTAL_BYTES "空闲空间(M)",
       F.MAX_BYTES "最大块(M)"
  FROM (SELECT TABLESPACE_NAME,
               ROUND(SUM(BYTES) / (1024 * 1024), 2) TOTAL_BYTES,
               ROUND(MAX(BYTES) / (1024 * 1024), 2) MAX_BYTES
          FROM SYS.DBA_FREE_SPACE
         GROUP BY TABLESPACE_NAME) F,
       (SELECT DD.TABLESPACE_NAME,
               ROUND(SUM(DD.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB
          FROM SYS.DBA_DATA_FILES DD
         GROUP BY DD.TABLESPACE_NAME) D
 WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME
 ORDER BY 1;
– Oracle数据库整库大小
select sum(bytes)/1024/1024/1024 from dba_data_files;

– 实际数据文件大小

select sum(bytes/1024/1024/1024) from dba_segments where owner='IBP_HC';
select distinct owner from dba_segments;
select distinct segment_type from dba_segments;

–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 user_tables;
-- 显示指定用户所具有的系统权限
select * from dba_sys_privs where grantee='HUACHUANG';
–2:表
-- 查看当前用户下所有的表
select * from user_tables;
-- 查看指定用户下的所有表
select a.TABLE_NAME from all_tables a where a.OWNER = upper('IBP_AUTH');
-- 查看名称包含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 object_name,created from user_objects where object_name=upper('表名');
-- 查看某表的大小
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语句
select 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');
select text from user_views where view_name=upper('V_CUST_GRADE_ALL');

–6:同义词

 --查看同义词的名称
select * from user_synonyms;
-- 创建同义词
create synonym table_name for user2.table_name;
-- 权限不足问题解决(切换到user2用户下)
GRANT CREATE SYNONYM TO user1;

–7 约束条件

--查看某表的约束条件
select constraint_name, constraint_type,search_condition, r_constraint_name
from user_constraints where table_name = upper('&table_name');
–8 存储函数和过程

--查看函数和过程的状态

select object_name,status from user_objects where object_type='FUNCTION';
select object_name,status from user_objects where object_type='PROCEDURE';
--查看函数和过程的源代码
select text from all_source where owner=user and name=upper('&plsql_name');

–9:查看建表语句

SELECT DBMS_METADATA.GET_DDL('TABLE','TB_TRANSA_CASH_TRADING_INFO')FROM DUAL; (表名TABLE_NAME一定要来大写)



这篇关于查看Oracle当前用户下的(表,视图,同义词,索引等...)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!