qweewq123qwe 发表于 2018-10-21 12:20:00

常用SQL(三)

select * from DBA_DATAPUMP_JOBS;  
select job_name,state from dba_datapump_jobs;
  
select * from DBA_DATAPUMP_SESSIONS;
  

  
-- 查看当前连接到数据库的用户
  
select distinct username from v$session where username is not null group by username;
  

  
-- 查看当前数据库版本
  
select * from v$version
  

  
-- 查看所有表
  
select * from user_tables
  
select serial#, sid from v$session;
  

  
-- 显示用户信息(所属表空间)
  
select distinct default_tablespace,temporary_tablespace from dba_users
  

  
-- 查询oracle的连接数
  
select count(*) from v$session;
  

  
-- 查询oracle的并发连接数
  
select count(*) from v$session where status='ACTIVE';
  

  
-- 查看不同用户的连接数
  
select username,count(username) from v$session where username is not null
  
group by username;
  

  
-- 查看所有用户:
  
select * from all_users;
  

  
-- 查看用户或角色系统权限(直接赋值给用户或角色的系统权限):
  
select * from dba_sys_privs;
  
select * from user_sys_privs;
  

  
-- 查看角色(只能查看登陆用户拥有的角色)所包含的权限
  
select * from role_sys_privs;
  

  
-- 查看用户对象权限:
  
select * from dba_tab_privs;
  
select * from all_tab_privs;
  
select * from user_tab_privs;
  

  
-- 查看所有角色:
  
select * from dba_roles;
  

  
-- 查看用户或角色所拥有的角色:
  
select * from dba_role_privs;
  
select * from user_role_privs;
  

  
-- 查看哪些用户有sysdba或sysoper系统权限(查询时需要相应权限)
  
select * from V$PWFILE_USERS;
  

  
-- 查看表空间的名称及大小
  
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;
  

  
-- 查看表空间物理文件的名称及大小
  
SELECT tablespace_name,
  
file_id,
  
file_name,
  
round(bytes / (1024 * 1024), 0) total_space
  
FROM dba_data_files
  
ORDER BY tablespace_name;
  

  
-- 查看回滚段名称及大小
  
SELECT segment_name,
  
tablespace_name,
  
r.status,
  
(initial_extent / 1024) initialextent,
  
(next_extent / 1024) nextextent,
  
max_extents,
  
v.curext curextent
  
FROM dba_rollback_segs r, v$rollstat v
  
WHERE r.segment_id = v.usn(+)
  
ORDER BY segment_name;
  

  
-- 查看控制文件
  
SELECT NAME FROM v$controlfile;
  

  
-- 查看日志文件
  
SELECT MEMBER FROM v$logfile;
  

  
-- 查看表空间的使用情况
  
SELECT SUM(bytes) / (1024 * 1024) AS free_space, tablespace_name
  
FROM dba_free_space
  
GROUP BY tablespace_name;
  
SELECT a.tablespace_name,
  
a.bytes total,
  
b.bytes used,
  
c.bytes free,
  
(b.bytes * 100) / a.bytes "% USED ",
  
(c.bytes * 100) / a.bytes "% FREE "
  
FROM sys.sm$ts_avail a, sys.sm$ts_used b, sys.sm$ts_free c
  
WHERE a.tablespace_name = b.tablespace_name
  
AND a.tablespace_name = c.tablespace_name;
  

  
-- 查看数据库库对象
  
SELECT owner, object_type, status, COUNT(*) count#
  
FROM all_objects
  
GROUP BY owner, object_type, status;
  

  
-- 查看数据库的版本 
  
SELECT version
  
FROM product_component_version
  
WHERE substr(product, 1, 6) = 'Oracle';
  

  
-- 查看数据库的创建日期和归档方式
  
SELECT created, log_mode, log_mode FROM v$database;


页: [1]
查看完整版本: 常用SQL(三)