oracle经常用到的 语句(未完待续)

来源:互联网 发布:java闰年的判断 编辑:程序博客网 时间:2024/04/29 09:37

 1、查询所有表空间的大小和名称

select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size

from dba_tablespaces t, dba_data_files d

where t.tablespace_name = d.tablespace_name

group by t.tablespace_name

2、查看表空间物理文件的名称和大小
select tablespace_name, file_id, file_name,

round(bytes/(1024*1024),0) total_space

from dba_data_files

order by tablespace_name;

3、查看表空间的使用状况
select sum(bytes)/(1024*1024) free_space,tablespace_name

from dba_free_space

group by tablespace_name;

4、查询用户属于哪个表空间

select   username,default_tablespace from dba_users order by username;

5、知道表空间名,显示该表空间下包含的表

select * from all_tables where tablespace_name='表空间名' (大写)

6、知道表名,查看属于哪个表空间

select tablespace_name,table_name from user_tables where table_name='表名称';

 7、两个用户间表的复制和查询,授权语句

grant select any table to  用户;

select 'grant all on'||table_name||'to user2;'from all_tables where owner=upper('user1');

8、查询本用户下所有的表和试图

select * from user_tab_comments  ;

9、将用户移动到指定表空间

alter user andyu default tablespace test;

10、查看表的约束与索引

select  table_name,constraint_name,constraint_type from user_constraints(或者DBA_constraints)

 where table_name='大写表名'

select * from user_indexes (或者all_indexes)

where table_name='大写表名'
11、查询数据文件

SELECT FILE_ID,FILE_NAME FROM DBA_DATA_FILES;

12、查询表空间及其关联的数据文件

select ts.tablespace_name,df.file_name,df.file_id,df.status
from dba_tablespaces ts,
(select tablespace_name,file_id,file_name,status
from dba_data_files
union all
select tablespace_name,file_id,file_name,status
from dba_temp_files) df
where ts.tablespace_name=df.tablespace_name

 13、权限与角色的查询

① select * from dba_roles;查询有多少角色

② select * from dba_role_privs where grantee='用户名(大写)' 用户拥有的角色

③select * from dba_sys_privs where grantee='角色名(大写)' 角色的系统权限

     select * from dba_tab_privs where grantee='角色名(大写)' 角色的对象权限

   识别’低效执行’的SQL语句

14、用下列SQL工具找出低效SQL:
SELECT EXECUTIONS , DISK_READS, BUFFER_GETS,
        ROUND((BUFFER_GETS-DISK_READS)/BUFFER_GETS,2) Hit_radio,
        ROUND(DISK_READS/EXECUTIONS,2) Reads_per_run,
        SQL_TEXT
FROM   V$SQLAREA
WHERE  EXECUTIONS>0
AND     BUFFER_GETS > 0 
AND (BUFFER_GETS-DISK_READS)/BUFFER_GETS < 0.8 
ORDER BY 4 DESC;

原创粉丝点击